home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / Text-Viewer / MSWordView / mswordview_src / mswordview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-06  |  154.9 KB  |  6,164 lines

  1. /*
  2. Released under GPL, written by Caolan.McNamara@ul.ie.
  3.  
  4. Copyright (C) 1998 
  5.     Caolan McNamara
  6.  
  7. Real Life: Caolan McNamara           *  Doing: MSc in HCI
  8. Work: Caolan.McNamara@ul.ie          *  Phone: +353-61-202699
  9. URL: http://skynet.csn.ul.ie/~caolan *  Sig: an oblique strategy
  10. How would you have done it?
  11. */
  12.  
  13. /*
  14. this software no longer requires laola
  15. */
  16.  
  17. char *version="mswordview 0.5.2";
  18.  
  19. /*
  20.  
  21. this code is often all over the shop, being more of an organic entity
  22. that a carefully planed piece of code, so no laughing there at the back!
  23.  
  24. and send me patches by all means, but think carefully before sending me
  25. a patch that doesnt fix a bug or add a feature but instead just changes
  26. the style of coding, i.e no more thousand line patches that fix my 
  27. indentation. (i like it this way)
  28.  
  29. */
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <ctype.h>
  34. #include <string.h>
  35. #include <time.h>
  36. #include <math.h>
  37. #include <limits.h>
  38. #include "config.h"
  39. #include "mswordview.h"
  40. #include "roman.h"
  41. #include "utf.h"
  42.  
  43. extern int nostyles;
  44. extern ATRD *key_atrd;
  45.  
  46. /*ok i got impatient*/
  47. obj_by_spid *picblips=NULL;
  48.  
  49. int notablewidth=0;
  50. int madeinmac=0;
  51.  
  52. int list_author_key=0;
  53.  
  54. int nofontfaces=0;
  55. int riskbadole=0;
  56. int NORMAL=20;
  57. int inunderline = 0;
  58. int inbold = 0;
  59. int incenter= 0;
  60. int inrightjust= 0;
  61. int inblink= 0;
  62. int inah1= 0;
  63. int inaheaderfooter=0;
  64. int initalic = 0;
  65. int inafont= 0;
  66. int pagenumber=1;
  67. int sectionpagenumber=1;
  68. int sectionno=1;
  69. int insuper = 0;
  70. int insub = 0;
  71. int inatable=0;
  72. float tabsize=-1;
  73. int cellempty=1;
  74. int inarow=0;
  75. int inacell=0;
  76. int inalist = 0;
  77. int doannos=1;
  78.  
  79. int noheaders=0;
  80.  
  81. int deferrednewpage=0;
  82.  
  83. S16 lastcellwidth[65];
  84. S16 lastrowlen=0;
  85.  
  86. int colcount;
  87. int rowcount;
  88.  
  89. U32 mainend;
  90. U32 lastlistid =0;
  91. int listvalue[9];
  92. int currentfontsize;
  93. int currentfontcode=-1;
  94.  
  95. sep *currentsep=NULL;
  96.  
  97. int newline=1;
  98. int inacolor;
  99. char incolor[8]="";
  100. char backgroundcolor[8]="";
  101.  
  102. U8 chps=0;
  103.  
  104. int padding=0;
  105. int verpadding=0;
  106. int ignoreheadings=0;
  107. long int cp=0;
  108. long int realcp=0;
  109. static U8 header;
  110. int breakcount;
  111. int footnotehack=0;
  112. int instrike=0;
  113.  
  114. char *symbolurl=NULL;
  115. char *imagesurl=NULL;
  116. char *imagesdir=NULL;
  117. char *wingdingurl=NULL;
  118. char *patternurl=NULL;
  119. char *outputfilename=NULL;
  120. char *errorfilename=NULL;
  121. char *filename=NULL;
  122. FILE *outputfile=NULL;
  123. FILE *erroroutput=NULL;
  124.  
  125.  
  126. void usage( void )
  127.     {
  128.     fprintf(erroroutput,"Usage: mswordview [-v] [--version] [-n] [--nocredits] [-c] [--corehtmlonly]\n"
  129.                         "[-t seconds] [--timeout seconds] [-f points] [--defaultfontsize points] [-p url]\n"
  130.                         "[--patternurl url] [-s url] [--symbolurl url] [-d url] [--wingdingurl url] [-h]\n"
  131.                         "[--ignoreheadings] [-m] [--mainonly] [-b] [--riskbadole] [-e] [--nofontfaces]\n"
  132.                         "[-o] [--outputfile] [-g erroroutputfile] [--errorfile erroroutputfile] \n"
  133.                         "[-y tabvalue] [--tabsize tabvalue] [-i] [--imagesdir] [-j] [--imagesurl] \n"
  134.                         "[-k] [--notablewidth] filename.doc\n");
  135.     exit(-1);
  136.     }
  137.  
  138.  
  139.  
  140. int main(int argc,char **argv)
  141.     {
  142.     
  143.     
  144.     
  145.     
  146.     
  147.     
  148.     int ret=0;
  149.     int timeout=-1;
  150.     char *endptr;
  151.     char *buffer;
  152.     char fileinbuf[1024];
  153.     
  154.     FILE *filein;
  155.  
  156.     FILE *mainfd=NULL;
  157.     FILE *tablefd0=NULL;
  158.     FILE *tablefd1=NULL;
  159.     FILE *data=NULL;
  160.  
  161.     int c;
  162.     int tail=1;
  163.     int core=1;
  164.     int index=0;
  165.  
  166.     chp achp;
  167.     pap apap;
  168.  
  169.     static struct option long_options[] = 
  170.         {
  171.         { "version",0 , 0, 'v' },
  172.         { "corehtmlonly",0 , 0, 'c' },
  173.         { "nocredits",0 , 0, 'n' },
  174.         { "noannotations",0 , 0, 'a' },
  175.         { "timeout",1 , 0, 't' },
  176.         { "horizontalwhite",1,0,'w'},
  177.         { "verticalwhite",1,0,'u'},
  178.         { "symbolurl", 1,0,'s'},
  179.         { "wingdingurl", 1,0,'d'},
  180.         { "imagesdir", 1,0,'i'},
  181.         { "imagesurl", 1,0,'j'},
  182.         { "ignoreheadings", 0,0,'h'},
  183.         { "defaultfontsize", 1,0,'f'},
  184.         { "mainonly", 0,0,'m' },
  185.         { "riskbadole", 0,0,'b'},
  186.         { "nofontfaces", 0,0,'e'},
  187.         { "outputfile", 1,0,'c'},
  188.         { "errorfile", 1,0,'g'},
  189.         { "patternurl",1,0,'p'},
  190.         { "tabsize",1,0,'y'},
  191.         { "notablewidth",1,0,'k'},
  192.         { 0,      0, 0, '0' },
  193.         };
  194.  
  195.  
  196.     erroroutput=stderr;
  197.  
  198.  
  199.     while (1)
  200.         {
  201.         c = getopt_long (argc, argv, "abcd:ef:g:hi:j:kmno:p:s:t:u:vw:y:", long_options, &index);
  202.         if (c == -1)
  203.             break;
  204.         switch(c)
  205.             {
  206.             case 'f':
  207.                 if (optarg)
  208.                     {
  209.                        NORMAL = strtol(optarg, &endptr, 10);
  210.                        if ((*optarg == '\0') || (*endptr  != '\0'))
  211.                         {
  212.                         fprintf(erroroutput,"f option must be followed with a number\n");
  213.                         NORMAL=20;
  214.                         }
  215.                     else
  216.                         NORMAL*=2;
  217.                      }
  218.                 else 
  219.                     {
  220.                     fprintf(erroroutput,"no val given for defaultfontsize (-f) \n");
  221.                     NORMAL=20;
  222.                     }
  223.                 break;
  224.             case 'v':
  225.                 printf("%s, by Caolan.McNamara@ul.ie\n\nWeb pages for updates exist at \nhttp://www.gnu.org/~caolan/docs/MSWordView.html\nhttp://www.csn.ul.ie/~caolan/docs/MSWordView.html\n\n", version);
  226.                 exit (0);
  227.                 break;
  228.             case 'k':
  229.                 notablewidth=1;
  230.                 break;
  231.             case 'm':
  232.                 noheaders=1;
  233.                 break;
  234.             case 'e':
  235.                 nofontfaces=1;
  236.                 break;
  237.             case 'b':
  238.                 riskbadole=1;
  239.                 break;
  240.             case 'h':
  241.                 ignoreheadings=1;
  242.                 break;
  243.             case 'n':
  244.                 tail=0;
  245.                 break;    
  246.             case 'a':
  247.                 doannos=0;
  248.                 break;    
  249.             case 'u':
  250.                 if (optarg)
  251.                     {
  252.                        verpadding = strtol(optarg, &endptr, 10);
  253.                        if ((*optarg == '\0') || (*endptr  != '\0'))
  254.                         {
  255.                         fprintf(erroroutput,"u option must be followed with a number\n");
  256.                         verpadding=0;
  257.                         }
  258.                     if ((verpadding < 0) || (verpadding > 2))
  259.                         {
  260.                         fprintf(erroroutput,"u option accepts on 0,1,2 as an argument, not %d\n",verpadding);
  261.                         verpadding=0;
  262.                         }
  263.                      }
  264.                 else 
  265.                     {
  266.                     fprintf(erroroutput,"no val given for verticalpadding (-u) \n");
  267.                     verpadding=0;
  268.                     }
  269.                 
  270.                 
  271.                 break;    
  272.             case 't':
  273.                 if (optarg)
  274.                     {
  275.                        timeout = strtol(optarg, &endptr, 10);
  276.                        if ((*optarg == '\0') || (*endptr  != '\0'))
  277.                         fprintf(erroroutput,"t option must be followed with a number\n");
  278.                      }
  279.                 else 
  280.                     fprintf(erroroutput,"no val given for timeout option (-t)\n");
  281.                 break;
  282.             case 'o':
  283.                 if (optarg)
  284.                     {
  285.                     outputfilename = malloc(strlen(optarg)+1);
  286.                     if (outputfilename == NULL)
  287.                         {
  288.                         fprintf(erroroutput,"no mem\n");
  289.                         exit(-1);
  290.                         }
  291.                     strcpy(outputfilename,optarg);
  292.                     }
  293.                 else
  294.                     {
  295.                     fprintf(erroroutput,"no val given, assuming standard\n");
  296.                     }
  297.                 break;
  298.             case 'g':
  299.                 if (optarg)
  300.                     {
  301.                     errorfilename = malloc(strlen(optarg)+1);
  302.                     if (errorfilename == NULL)
  303.                         {
  304.                         fprintf(erroroutput,"no mem\n");
  305.                         exit(-1);
  306.                         }
  307.                     strcpy(errorfilename,optarg);
  308.                     }
  309.                 else
  310.                     {
  311.                     fprintf(erroroutput,"no val given, assuming standard\n");
  312.                     }
  313.                 break;
  314.             case 'j':
  315.                 if (optarg)
  316.                     {
  317.                     imagesurl = malloc(strlen(optarg)+1);
  318.                     if (imagesurl == NULL)
  319.                         {
  320.                         fprintf(erroroutput,"no mem\n");
  321.                         exit(-1);
  322.                         }
  323.                     strcpy(imagesurl,optarg);
  324.                     }
  325.                 else
  326.                     fprintf(erroroutput,"no val given for imagesurl\n");
  327.                 break;
  328.             case 'i':
  329.                 if (optarg)
  330.                     {
  331.                     imagesdir = malloc(strlen(optarg)+1);
  332.                     if (imagesdir == NULL)
  333.                         {
  334.                         fprintf(erroroutput,"no mem\n");
  335.                         exit(-1);
  336.                         }
  337.                     strcpy(imagesdir,optarg);
  338.                     }
  339.                 else
  340.                     fprintf(erroroutput,"no val given for imagesdir\n");
  341.                 break;
  342.             case 's':
  343.                 if (optarg)
  344.                     {
  345.                     symbolurl = malloc(strlen(optarg)+1);
  346.                     if (symbolurl == NULL)
  347.                         {
  348.                         fprintf(erroroutput,"no mem\n");
  349.                         exit(-1);
  350.                         }
  351.                     strcpy(symbolurl,optarg);
  352.                     }
  353.                 else
  354.                     fprintf(erroroutput,"no val given for symbolurl\n");
  355.                 break;
  356.             case 'p':
  357.                 if (optarg)
  358.                     {
  359.                     patternurl = malloc(strlen(optarg)+1);
  360.                     if (patternurl == NULL)
  361.                         {
  362.                         fprintf(erroroutput,"no mem\n");
  363.                         exit(-1);
  364.                         }
  365.                     strcpy(patternurl,optarg);
  366.                     }
  367.                 else
  368.                     fprintf(erroroutput,"no val given for patternurl\n");
  369.                 break;
  370.             case 'd':
  371.                 if (optarg)
  372.                     {
  373.                     wingdingurl = malloc(strlen(optarg)+1);
  374.                     if (wingdingurl == NULL)
  375.                         {
  376.                         fprintf(erroroutput,"no mem\n");
  377.                         exit(-1);
  378.                         }
  379.                     strcpy(wingdingurl,optarg);
  380.                     }
  381.                 else
  382.                     fprintf(erroroutput,"no val given for wingdingurl\n");
  383.                 break;
  384.             case 'w':
  385.                 if (optarg)
  386.                     {
  387.                        padding = strtol(optarg, &endptr, 10);
  388.                        if ((*optarg == '\0') || (*endptr  != '\0'))
  389.                         {
  390.                         fprintf(erroroutput,"w option must be followed with a number\n");
  391.                         padding=0;
  392.                         }
  393.                     if ((padding < 0) || (padding > 5))
  394.                         {
  395.                         fprintf(erroroutput,"w option must be followed with a number from 0..5\n");
  396.                         padding=0;
  397.                         }
  398.                      }
  399.                 else 
  400.                     {
  401.                     fprintf(erroroutput,"no val given for horizontalwhite option (-w)\n");
  402.                     padding=0;
  403.                     }
  404.                 break;
  405.             case 'y':
  406.                 if (optarg)
  407.                     {
  408.                        tabsize = strtod(optarg, &endptr);
  409.                        if ((*optarg == '\0') || (*endptr  != '\0'))
  410.                         {
  411.                         fprintf(erroroutput,"tabsize (y) option must be followed with a number\n");
  412.                         tabsize=-1;
  413.                         }
  414.                      }
  415.                 else 
  416.                     {
  417.                     fprintf(erroroutput,"no val given for defaultfontsize (-f) \n");
  418.                     tabsize = -1;
  419.                     }
  420.                 break;
  421.             case 'c':
  422.                 core=0;
  423.                 break;
  424.             default:
  425.                 usage();
  426.                 break;
  427.             }
  428.         }
  429.  
  430.     if (argc <= optind) 
  431.         {
  432.         usage();
  433.         }
  434.  
  435.     if (errorfilename != NULL)
  436.         {
  437.         erroroutput = fopen(errorfilename,"w");
  438.         if (erroroutput== NULL)
  439.             {
  440.             fprintf(erroroutput,"couldnt open %s for writing\n",errorfilename);
  441.             return(-1);
  442.             }
  443.         }
  444.     else
  445.         erroroutput = erroroutput;
  446.         
  447.  
  448.     if (optind < argc)
  449.         filename = strdup(argv[optind]);
  450.     else 
  451.         filename =NULL;
  452.  
  453.     if (filename == NULL)
  454.         {
  455.         fprintf(erroroutput,"The file %s doesn't exist\n",filename);
  456.         return(ret);
  457.         }
  458.  
  459.     /*set SIGCHLD handled*/
  460.     signal_handle (SIGCHLD, reaper);
  461.  
  462.     currentfontsize = NORMAL;
  463.  
  464.     
  465.     if (timeout != -1)
  466.         {
  467.         signal_handle (SIGALRM, timeingout);
  468.         /*well abort after this number of seconds*/
  469.         alarm(timeout);
  470.         }
  471.  
  472.  
  473.     if (tabsize == -1)
  474.         {
  475.         if ( (padding == 0) || (padding == 3))
  476.             tabsize=SPACEPIXELS;
  477.         else
  478.             tabsize=8;
  479.         }
  480.     else
  481.         if ( (padding == 0) || (padding == 3))
  482.             tabsize=tabsize/8;
  483.  
  484.  
  485.     ret = myOLEdecode(filename,&mainfd,&tablefd0,&tablefd1,&data);
  486.     if (ret)
  487.         {
  488.         fprintf(erroroutput,"Sorry main document stream couldnt be found in doc \n%s\n",filename);
  489.         fprintf(erroroutput,"if this *is* a word 8 file, it appears to be corrupt\n");
  490.         fprintf(erroroutput,"remember, mswordview cannot handle rtf,word 6 or word 7 etc\n");
  491.  
  492.         buffer = (char *) malloc(strlen(filename) +3 + strlen("file "));
  493.         sprintf(buffer,"file \"%s\"",filename);
  494.         filein = popen(buffer,"r");
  495.         if (filein != NULL)
  496.             {
  497.             fprintf(erroroutput,"for your information, the utility \n\"file %s\" reports ...\n\n",filename);
  498.             while (fgets(fileinbuf,1024,filein) != NULL)
  499.                 fprintf(erroroutput,"%s",fileinbuf);
  500.             }
  501.         free(buffer);
  502.         ret=10;
  503.         if (riskbadole) 
  504.             ret = decode_word8(mainfd,tablefd0,tablefd1,data,core);
  505.         }
  506.     else
  507.         {
  508.         ret = decode_word8(mainfd,tablefd0,tablefd1,data,core);
  509.         myfreeOLEtree();
  510.         }
  511.  
  512.     if ((ret != -1) && (ret != 10))
  513.         {
  514.         if (inacell)
  515.             {
  516.             init_chp(&achp);
  517.             init_pap(&apap);
  518.             decode_e_chp(&achp);
  519.             decode_e_specials(&apap,&achp,NULL);
  520.  
  521.             fprintf(outputfile,"\n</TD>\n");
  522.             backgroundcolor[0] = '\0';
  523.             }
  524.  
  525.         if (inarow)
  526.             fprintf(outputfile,"\n</tr>\n");
  527.         if (inatable)
  528.             fprintf(outputfile,"\n</table>\n");
  529.         do_indent(&apap);
  530.  
  531.         init_chp(&achp);
  532.         init_pap(&apap);
  533.         decode_e_chp(&achp);
  534.         if (inafont)
  535.             {
  536.             fprintf(outputfile,"</font>\n");
  537.             inafont=0;
  538.             }
  539.         decode_e_specials(&apap,&achp,NULL);
  540.  
  541.         fprintf(outputfile,"\n<br><img src=\"%s/documentend.gif\"><br>\n",patterndir());
  542.  
  543.  
  544.         if (tail)
  545.             {
  546.             fprintf(outputfile,"<hr><p>\nDocument converted from word 8 by \n<a href=\"http://www.csn.ul.ie/~caolan/docs/MSWordView.html\">MSWordView</a> (%s)<br>\n",version);
  547.             fprintf(outputfile,"MSWordView written by <a href=\"mailto:Caolan.McNamara@ul.ie\">Caolan McNamara</a>\n</body>\n");
  548.             }
  549.         if (core)
  550.             fprintf(outputfile,"\n</html>\n");
  551.         }
  552.     cleanupglobals();
  553.     
  554.     if (ret == 10) /*known reason as to why conversion did not occur*/
  555.         ret=0;
  556.     return(ret);
  557.     }
  558.  
  559. void cleanupglobals(void)
  560.     {
  561.     obj_by_spid *freeme=NULL;
  562.  
  563.     if ((outputfile!=NULL) && (outputfile!=stdout))
  564.         fclose(outputfile);
  565.  
  566.     if ((erroroutput!=NULL) && (erroroutput!=stderr))
  567.         fclose(erroroutput);
  568.  
  569.     if (picblips != NULL)
  570.         {
  571.         freeme = picblips;
  572.         picblips = picblips->next;
  573.         if (freeme->filename != NULL)
  574.             free(freeme->filename);
  575.         free(freeme);
  576.         }
  577.     
  578.     if (symbolurl!=NULL)
  579.         free(symbolurl);
  580.     if (imagesurl!=NULL)
  581.         free(imagesurl);
  582.     if (imagesdir!=NULL)
  583.         free(imagesdir);
  584.     if (wingdingurl!=NULL)
  585.         free(wingdingurl);
  586.     if (patternurl!=NULL)
  587.         free(patternurl);
  588.     if (outputfilename!=NULL)
  589.         free(outputfilename);
  590.     if (errorfilename!=NULL)
  591.         free(errorfilename);
  592.     if (filename!=NULL)
  593.         free(filename);
  594.     if (key_atrd != NULL)
  595.         free(key_atrd);
  596.     }
  597.  
  598. int decode_word8(FILE *mainfd,FILE *tablefd0,FILE *tablefd1,FILE *data,int core)
  599.     {
  600.     U32 i,j,k;
  601.     
  602.     U16 wIdent,nFib,nProduct,lid,pnNext,nFibBack,chse,chseTables;
  603.     U32 lKey,fcMin,fcMac,cbMac,fcSpare,ccpMcr,ccpTxbx,ccpSpare2,fcStshfOrig,lcbStshfOrig;
  604.     textportions portions;
  605.     U8 fields1,fields2,envr,reserved;
  606.     U8 iscomplex=0;
  607.     U32 pnPapFirst,cpnBtePap;
  608.     U32 pnChpFirst,cpnBteChp;
  609.     U32 pnLvcFirst,cpnBteLvc;
  610.     U32 fcPlcfbtePapx,lcbPlcfbtePapx;
  611.     U32 fcPlcfbteChpx,lcbPlcfbteChpx;
  612.     U32 *plcfbtePapx;
  613.     U32 *plcfbteChpx;
  614.     U32 chpintervals;
  615.     U32 intervals;
  616.     U32 fcClx,lcbClx;
  617.     U32 fcPlcffldMom,lcbPlcffldMom;
  618.     U32 fcPlcffldHdr,lcbPlcffldHdr;
  619.     U32 fcPlcffldFtn,lcbPlcffldFtn;
  620.     U32 fcSttbfffn,lcbSttbfffn;
  621.     ffn fontnamelist;
  622.     ffn *tempnames;
  623.     ffn *freenames;
  624.     obj_by_spid *freeme=NULL;
  625.     list_def *free_def,*free_def2;
  626.     U32 *cp_plcfld;
  627.     U8 *fld_plcfld;
  628.     U32 *cp_plcfld2;
  629.     U8 *fld_plcfld2;
  630.     U32 *cp_plcfld3;
  631.     U8 *fld_plcfld3;
  632.     U32 *cp_plcfld4;
  633.     U8 *fld_plcfld4;
  634.     U32 *cp_plcfld5;
  635.     U8 *fld_plcfld5;
  636.     U8 len;
  637.     
  638.     
  639.     
  640.     field_info *all_fields[5];
  641.     field_info main_fields;
  642.     field_info header_fields;
  643.     field_info footnote_fields;
  644.     field_info annotation_fields;
  645.     field_info endnote_fields;
  646.     U32 fcPlcfLst,lcbPlcfLst;
  647.     U32 fcPlfLfo,lcbPlfLfo;
  648.     U32 fcSttbFnm,lcbSttbFnm;
  649.     U32 fcPlcffndRef;
  650.     U32 fcPlcffndTxt;
  651.     U32 lcbPlcffndRef;
  652.     U32 lcbPlcffndTxt;
  653.     /*begin annotations*/
  654.     U32 fcPlcfandRef,lcbPlcfandRef;
  655.     U32 fcPlcfandTxt,lcbPlcfandTxt;
  656.     U32 fcPlcffldAtn,lcbPlcffldAtn;
  657.     U32 fcGrpXstAtnOwners,lcbGrpXstAtnOwners;
  658.     
  659.  
  660.     
  661.     stringgroup *freegroup;
  662.     /*end annotations*/
  663.     /*begin endnotes*/
  664.     U32 fcPlcfendRef,lcbPlcfendRef;
  665.     U32 fcPlcfendTxt,lcbPlcfendTxt;
  666.     U32 fcPlcffldEdn,lcbPlcffldEdn;
  667.     
  668.     
  669.     /*end endnotes*/
  670.     /*begin section table*/
  671.     U32 fcPlcfsed,lcbPlcfsed;
  672.     /*end section table*/
  673.  
  674.     
  675.     U32 ccpHdrTxbx;
  676.     
  677.     
  678.     
  679.  
  680.     U32 fcPlcspaMom,lcbPlcspaMom; 
  681.     /*we use these to get spids, and then suck the pictures out of the the resulting tables found though fcDggInfo ??*/
  682.     U32 fcDggInfo,lcbDggInfo;
  683.  
  684.     
  685.     
  686.  
  687.     U32 stsh,stshlen;
  688.     
  689.     list_info a_list_info;
  690.     style *masterstylesheet=NULL;
  691.  
  692.     FILE *tablefd;
  693.  
  694.     int notfinished;
  695.  
  696.     if (mainfd == NULL)
  697.         {
  698.         fprintf(erroroutput,"There was no document stream, this is probably not a word file at all\n");
  699.         return(10);
  700.         }
  701.  
  702.  
  703.     if (outputfilename == NULL)
  704.         {
  705.         outputfilename = malloc(strlen(filename) + strlen(".html") + 1);
  706.         if (outputfilename == NULL)
  707.             {
  708.             fprintf(erroroutput,"no mem\n");
  709.             return(-1);
  710.             }
  711.         sprintf(outputfilename,"%s%s",filename,".html");
  712.         }
  713.  
  714.     if (strcmp(outputfilename,"-"))
  715.         {
  716.         outputfile = fopen(outputfilename,"w");
  717.         if (outputfile == NULL)
  718.             {
  719.             fprintf(erroroutput,"couldnt open %s for writing\n",outputfilename);
  720.             return(-1);
  721.             }
  722.         }
  723.     else
  724.         outputfile = stdout;
  725.     
  726.  
  727.     fseek(mainfd,0,SEEK_END);
  728.     mainend = ftell(mainfd);
  729.     error(erroroutput,"the end of the stream is %x\n",mainend);
  730.     fseek(mainfd,0,SEEK_SET);
  731.     
  732.     wIdent=read_16ubit(mainfd);
  733.     nFib=read_16ubit(mainfd);
  734.     nProduct=read_16ubit(mainfd);
  735.  
  736.  
  737.     if (nFib >= 101)
  738.         error(erroroutput,"written by word >= 6, exactly %x\n",nProduct);
  739.     else
  740.         error(erroroutput,"written by word < 6, exactly %x\n",nProduct);
  741.  
  742.     if ((nProduct >> 8) == 0xe0)
  743.         {
  744.         fprintf(erroroutput,"this is an unsupported word 7 doc, sorry\nthis converter is solely for word8 at the moment\ntry laola (http://wwwwbs.cs.tu-berlin.de/~schwartz/pmh/laola.html) it might get some text out of it\n");
  745.         return(10);
  746.         }
  747.     else if ((nProduct >> 8) == 0xc0)
  748.         {
  749.         fprintf(erroroutput,"this is an unsupported (as of yet) word 6 doc, sorry\nthis converter is solely for word8 at the moment\ntry word2x (http://word2x.astra.co.uk/) for that\n");
  750.         return(10);
  751.         }
  752.     else if ((nProduct >> 8) != 0x00)
  753.         fprintf(erroroutput,"this doesnt appear to be a word 8 doc, but going ahead anyway, expect disaster!!\n");
  754.  
  755.     lid=read_16ubit(mainfd);
  756.     pnNext=read_16ubit(mainfd);
  757.     fields1 = getc(mainfd);
  758.     error(erroroutput,"wIdent is %d,nFib is %d, nProduct is %d, lid is %d, pnNext? is %d\n",wIdent,nFib,nProduct,lid,pnNext);
  759.         
  760.     if (fields1 & 0x01)
  761.         error(erroroutput,"mainfdot\n");
  762.     if (fields1 & 0x02)
  763.         error(erroroutput,"fGlsy\n");
  764.     if (fields1 & 0x04)
  765.         {
  766.         error(erroroutput,"fComplex\n");
  767.         iscomplex=1;
  768.         error(erroroutput,"complex doc, here we go!\n");
  769.         }
  770.     if (fields1 & 0x08)
  771.         error(erroroutput,"fHasPic\n");
  772.     fields1 &= 0xF0;
  773.     fields1 = fields1 >> 4;
  774.     error(erroroutput,"no od saves is %d\n",fields1);
  775.     fields2 = getc(mainfd);
  776.     if (fields2 & 0x01)
  777.         {
  778.         error(erroroutput,"fEncrypted\n");
  779.         fprintf(erroroutput,"This file is encrypted, mswordview currently cannot handle encrypted files\n");
  780.         return(10);
  781.         }
  782.  
  783.     if (fields2 & 0x02)
  784.         {
  785.         tablefd = tablefd1;
  786.         error(erroroutput,"use 1Table stream\n");
  787.         }
  788.     else
  789.         {
  790.         tablefd = tablefd0;
  791.         error(erroroutput,"use 0Table stream\n");
  792.         }
  793.  
  794.     if (fields2 & 0x04)
  795.         error(erroroutput,"fReadOnlyRecommedned\n");
  796.     if (fields2 & 0x08)
  797.         error(erroroutput,"fWriteReservation\n");
  798.     if (fields2 & 0x10)
  799.         error(erroroutput,"fEctChar\n");
  800.     nFibBack = read_16ubit(mainfd);
  801.     lKey = read_32ubit(mainfd);
  802.     envr = getc(mainfd);
  803.     error(erroroutput,"nFibback is %d, lKey is %ld\n",nFibBack,lKey);
  804.     if (envr == 0)
  805.         error(erroroutput,"created in winword\n");
  806.     else if (envr == 1)
  807.         error(erroroutput,"created in mac word\n");
  808.     madeinmac = envr;
  809.     reserved = getc(mainfd);
  810.     chse = read_16ubit(mainfd);
  811.     if (chse == 0)
  812.         error(erroroutput,"windows ansi\n");
  813.     else if (chse == 256)
  814.         error(erroroutput,"mac char set\n");
  815.     chseTables = read_16ubit(mainfd);
  816.     if (chseTables == 0)
  817.         error(erroroutput,"windows ansi\n");
  818.     else if (chseTables== 256)
  819.         error(erroroutput,"mac char set\n");
  820.  
  821.     fcMin = read_32ubit(mainfd);
  822.     fcMac = read_32ubit(mainfd);
  823.     fseek(mainfd,0x0040,SEEK_SET);
  824.     cbMac = read_32ubit(mainfd);
  825.     fcSpare= read_32ubit(mainfd);
  826.     fcSpare= read_32ubit(mainfd);
  827.  
  828.  
  829.     error(erroroutput,"first char is at %ld (%x)\n",fcMin,fcMin);
  830.     error(erroroutput,"last char is at %ld (%x)\n",fcMac,fcMac);
  831.  
  832.     portions.ccpText = read_32ubit(mainfd);
  833.     error(erroroutput,"the main doc text is of size %ld\n",portions.ccpText);
  834.     portions.ccpFtn = read_32ubit(mainfd);
  835.     error(erroroutput,"the footer text is of size %ld\n",portions.ccpFtn);
  836.     portions.ccpHdd = read_32ubit(mainfd);
  837.     error(erroroutput,"the header text is of size %ld\n",portions.ccpHdd);
  838.     portions.fcMin = fcMin;
  839.     portions.fcMac = fcMac;
  840.     ccpMcr = read_32ubit(mainfd);
  841.     portions.ccpAtn = read_32ubit(mainfd);
  842.     error(erroroutput,"the annotation text is size %ld\n",portions.ccpAtn);
  843.     portions.ccpEdn = read_32ubit(mainfd);
  844.     ccpTxbx = read_32ubit(mainfd);
  845.     ccpHdrTxbx = read_32ubit(mainfd);
  846.     ccpSpare2 = read_32ubit(mainfd);
  847.     fcStshfOrig = read_32ubit(mainfd);
  848.     lcbStshfOrig = read_32ubit(mainfd);
  849.     
  850.     /*attempt to list all paragraph bounds*/
  851.  
  852.     fseek(mainfd,112,SEEK_SET);    
  853.     pnChpFirst = read_32ubit(mainfd);
  854.     cpnBteChp = read_32ubit(mainfd);
  855.     error(erroroutput,"\n page of first different char type %d\nnumber of different character types %d\n",pnChpFirst,cpnBteChp);
  856.  
  857.  
  858.     fseek(mainfd,124,SEEK_SET);    
  859.     pnPapFirst = read_32ubit(mainfd);
  860.     cpnBtePap = read_32ubit(mainfd);
  861.     error(erroroutput,"\n page of first different para type %d\nnumber of different para types %d\n",pnPapFirst,cpnBtePap);
  862.     
  863.     fseek(mainfd,136,SEEK_SET);    
  864.     pnLvcFirst = read_32ubit(mainfd);
  865.     cpnBteLvc = read_32ubit(mainfd);
  866.     error(erroroutput,"\n page of first different lvc type %d\nnumber of different lvc types %d\n",pnLvcFirst,cpnBteLvc);
  867.     
  868.     fseek(mainfd,154,SEEK_SET);    
  869.     error(erroroutput,"the orig stsh is (%x), len (%x)\n",read_32ubit(mainfd),read_32ubit(mainfd));
  870.     
  871.     stsh = read_32ubit(mainfd);
  872.     stshlen = read_32ubit(mainfd);
  873.     error(erroroutput,"the new stsh is (%x), len (%x)\n",stsh,stshlen);
  874.  
  875.     masterstylesheet = decode_stylesheet(tablefd,stsh,stshlen);
  876.  
  877.     fcPlcffndRef=read_32ubit(mainfd);
  878.     lcbPlcffndRef=read_32ubit(mainfd);
  879.     fcPlcffndTxt=read_32ubit(mainfd);
  880.     lcbPlcffndTxt=read_32ubit(mainfd);
  881.  
  882.     fcPlcfandRef=read_32ubit(mainfd);
  883.     lcbPlcfandRef=read_32ubit(mainfd);
  884.     fcPlcfandTxt=read_32ubit(mainfd);
  885.     lcbPlcfandTxt=read_32ubit(mainfd);
  886.  
  887.  
  888.     error(erroroutput,"footnote: table offset of frd thingies (%x) of len %d\n",fcPlcffndRef,lcbPlcffndRef);
  889.     error(erroroutput,"there are %d footnotes\n",(lcbPlcffndRef-4)/6);
  890.  
  891.     error(erroroutput,"footnote: table offset for footnote text (%x) of len %d\n",fcPlcffndTxt,lcbPlcffndTxt);
  892.  
  893.  
  894.     portions.fndRef=NULL;
  895.     portions.fndFRD=NULL;
  896.     portions.fndTrueFRD=NULL;
  897.     portions.fndTxt=NULL;
  898.     portions.list_foot_no = 0;
  899.     portions.auto_foot=1;
  900.     portions.last_foot=0;
  901.  
  902.     portions.fndref_no=0;
  903.     portions.fndtxt_no=0;
  904.  
  905.     if (lcbPlcffndRef != 0)
  906.         {
  907.         portions.fndref_no=(lcbPlcffndRef-4)/6;
  908.         portions.fndRef = (U32 *) malloc( (portions.fndref_no+1) * sizeof(U32));
  909.         if (portions.fndRef == NULL)
  910.             {
  911.             fprintf(erroroutput,"NO MEM 1\n");
  912.             return(-1);
  913.             }
  914.  
  915.         portions.fndFRD = (S16 *) malloc( portions.fndref_no * sizeof(S16));
  916.         portions.fndTrueFRD = (S16 *) malloc( portions.fndref_no * sizeof(S16));
  917.         if ((portions.fndFRD == NULL) || (portions.fndTrueFRD == NULL))
  918.             {
  919.             fprintf(erroroutput,"NO MEM 2\n");
  920.             return(-1);
  921.             }
  922.         fseek(tablefd,fcPlcffndRef,SEEK_SET);
  923.         for(i=0;i<portions.fndref_no+1;i++)
  924.             {
  925.             portions.fndRef[i]=read_32ubit(tablefd);
  926.             error(erroroutput,"fndRef is %x\n",portions.fndRef[i]);
  927.             }
  928.         for(i=0;i<portions.fndref_no;i++)
  929.             {
  930.             portions.fndFRD[i]=(S16)read_16ubit(tablefd);
  931.             portions.fndTrueFRD[i]=portions.fndFRD[i];
  932.             error(erroroutput,"fndFRD is %d\n",portions.fndFRD[i]);
  933.             }
  934.         }
  935.  
  936.     if (lcbPlcffndTxt!= 0)
  937.         {
  938.         portions.fndtxt_no=lcbPlcffndTxt/4;
  939.         portions.fndTxt = (U32 *) malloc( portions.fndtxt_no  * sizeof(U32) );
  940.         if (portions.fndTxt == NULL)
  941.             {
  942.             fprintf(erroroutput,"NO MEM 3\n");
  943.             return(-1);
  944.             }
  945.         fseek(tablefd,fcPlcffndTxt,SEEK_SET);
  946.         for (i=0;i<portions.fndtxt_no;i++)
  947.             {
  948.             portions.fndTxt[i]=read_32ubit(tablefd);
  949.             error(erroroutput,"footnote->%x\n",portions.fndTxt[i]);
  950.             }
  951.         }
  952.  
  953.     portions.andref_no=0;
  954.     portions.andRef=NULL;
  955.     portions.andTxt=NULL;
  956.     portions.the_atrd=NULL;
  957.     portions.list_anno_no = 0;
  958.     portions.last_anno=0;
  959.  
  960.     error(erroroutput,"annotation offset is %x, len is %d\n",fcPlcfandRef,lcbPlcfandRef);
  961.     
  962.     if (lcbPlcfandRef != 0)
  963.         {
  964.         portions.andref_no=(lcbPlcfandRef-4)/34;
  965.         portions.andRef = (U32 *) malloc( (portions.andref_no+1)  * sizeof(U32) );
  966.         portions.the_atrd = (ATRD*) malloc( portions.andref_no  * sizeof(ATRD) );
  967.         if ((portions.andRef == NULL) || (portions.the_atrd == NULL))
  968.             {
  969.             fprintf(erroroutput,"NO MEM 3\n");
  970.             return(-1);
  971.             }
  972.         fseek(tablefd,fcPlcfandRef,SEEK_SET);
  973.         for (i=0;i<portions.andref_no+1;i++)
  974.             {
  975.             portions.andRef[i]=read_32ubit(tablefd);
  976.             error(erroroutput,"annotation to be found at %x\n",portions.andRef[i]);
  977.             }
  978.         for (i=0;i<portions.andref_no;i++)
  979.             {
  980.             for (j=0;j<10;j++)
  981.                 portions.the_atrd[i].xstUsrInitl[j] = read_16ubit(tablefd);
  982.             portions.the_atrd[i].ibst = read_16ubit(tablefd);
  983.             portions.the_atrd[i].ak = read_16ubit(tablefd);
  984.             portions.the_atrd[i].grfbmc = read_16ubit(tablefd);
  985.             portions.the_atrd[i].lTagBkmk = read_32ubit(tablefd);
  986.             }
  987.         /*ive ignored the ANLD structure for now*/
  988.         }
  989.  
  990.     if (lcbPlcfandTxt!= 0)
  991.         {
  992.         portions.andtxt_no=lcbPlcfandTxt/4;
  993.         portions.andTxt = (U32 *) malloc( portions.andtxt_no  * sizeof(U32) );
  994.         if (portions.andTxt == NULL)
  995.             {
  996.             fprintf(erroroutput,"NO MEM 3\n");
  997.             return(-1);
  998.             }
  999.         fseek(tablefd,fcPlcfandTxt,SEEK_SET);
  1000.         for (i=0;i<portions.andtxt_no;i++)
  1001.             {
  1002.             portions.andTxt[i]=read_32ubit(tablefd);
  1003.             error(erroroutput,"andTxt are %x\n",portions.andTxt[i]);
  1004.             }
  1005.         }
  1006.     
  1007.     fcPlcfsed=read_32ubit(mainfd);
  1008.     lcbPlcfsed=read_32ubit(mainfd);
  1009.     error(erroroutput,"section: table offset for section table (%x) of len %d\n",fcPlcfsed,lcbPlcfsed);
  1010.     portions.section_cps=NULL;
  1011.     portions.section_fcs=NULL;
  1012.     if (lcbPlcfsed >0)
  1013.         {
  1014.         portions.section_nos = (lcbPlcfsed-4)/16;
  1015.         error(erroroutput,"there are %d sections",portions.section_nos);
  1016.         portions.section_cps = (U32 *) malloc ((portions.section_nos+1) * sizeof(U32));
  1017.         portions.section_fcs = (U32 *) malloc ((portions.section_nos) * sizeof(U32));
  1018.         if ((portions.section_cps == NULL) || (portions.section_fcs ==  NULL))
  1019.             {
  1020.             error(erroroutput,"no mem for section_cps\n");
  1021.             return(-1);
  1022.             }
  1023.         fseek(tablefd,fcPlcfsed,SEEK_SET);
  1024.         for (i=0;i< portions.section_nos+1;i++)
  1025.             {
  1026.             portions.section_cps[i]=read_32ubit(tablefd);
  1027.             error(erroroutput,"section offsets are %x\n",portions.section_cps[i]);
  1028.             }
  1029.         for (i=0;i<portions.section_nos;i++)
  1030.             {
  1031.             read_16ubit(tablefd); /*internal*/
  1032.             portions.section_fcs[i] = read_32ubit(tablefd);
  1033.             error(erroroutput,"section file offsets are %x\n",portions.section_fcs[i]);
  1034.             read_16ubit(tablefd); /*internal*/
  1035.             read_32ubit(tablefd);
  1036.             }
  1037.         }
  1038.     
  1039.     fseek(mainfd,242,SEEK_SET);    
  1040.     portions.fcPlcfhdd = read_32ubit(mainfd);
  1041.     portions.lcbPlcfhdd = read_32ubit(mainfd);
  1042.     /*these point to the header/footer information thing*/
  1043.  
  1044.     error(erroroutput,"header in table offset of (%x), len is %d\n",portions.fcPlcfhdd,portions.lcbPlcfhdd);
  1045.     
  1046.     fcPlcfbteChpx = read_32ubit(mainfd);
  1047.     lcbPlcfbteChpx = read_32ubit(mainfd);
  1048.     error(erroroutput,"\nlocation of char description in table stream is %x\nsize is %ld\n",fcPlcfbteChpx,lcbPlcfbteChpx);
  1049.     plcfbteChpx = (U32 *) malloc(lcbPlcfbteChpx);
  1050.     fseek(tablefd,fcPlcfbteChpx,SEEK_SET);
  1051.     for (i=0;i<lcbPlcfbteChpx/4;i++)
  1052.         plcfbteChpx[i] = read_32ubit(tablefd);
  1053.     chpintervals = ((lcbPlcfbteChpx/4)-1)/2;
  1054.     error(erroroutput,"there are %d charrun intervals ? ending at ",chpintervals);
  1055.     for (i=1;i<chpintervals+1;i++)
  1056.         error(erroroutput,"%d (%d)", plcfbteChpx[i],plcfbteChpx[i+chpintervals]);
  1057.     error(erroroutput,"\n");
  1058.  
  1059.  
  1060.     fcPlcfbtePapx = read_32ubit(mainfd);
  1061.     lcbPlcfbtePapx = read_32ubit(mainfd);
  1062.     error(erroroutput,"\nlocation of para description in table stream is %ld\nsize is %ld\n",fcPlcfbtePapx,lcbPlcfbtePapx);
  1063.     /*go to location in table stream, */
  1064.     /*i believe that this is just an array of longs(4 bytes blocks)
  1065.      */
  1066.     plcfbtePapx = (U32 *) malloc(lcbPlcfbtePapx);
  1067.     fseek(tablefd,fcPlcfbtePapx,SEEK_SET);
  1068.     for (i=0;i<lcbPlcfbtePapx/4;i++)
  1069.         {
  1070.         plcfbtePapx[i] = read_32ubit(tablefd);
  1071.         error(erroroutput,"papx farting gives %x\n",plcfbtePapx[i]);
  1072.         }
  1073.     intervals = ((lcbPlcfbtePapx/4)-1)/2;
  1074.     error(erroroutput,"there are %d pragraph intervals ? ending at ",intervals);
  1075.     for (i=1;i<intervals+1;i++)
  1076.         error(erroroutput,"%d %x (%d)", plcfbtePapx[i], plcfbtePapx[i],plcfbtePapx[i+intervals]);
  1077.     error(erroroutput,"\n");
  1078.     fseek(mainfd,274,SEEK_SET);
  1079.     fcSttbfffn=read_32ubit(mainfd);
  1080.     lcbSttbfffn=read_32ubit(mainfd);
  1081.  
  1082.     if (lcbSttbfffn > 0)
  1083.         {
  1084.         tempnames = &fontnamelist;
  1085.         error(erroroutput,"have a table of font names (%x)\n",fcSttbfffn);
  1086.         fseek(tablefd,fcSttbfffn,SEEK_SET);
  1087.  
  1088.         j=0;
  1089.         /*seems to be a count of font names, followed by three blanks ?*/
  1090.         read_16ubit(tablefd);
  1091.         read_16ubit(tablefd);
  1092.         j=4;
  1093.         tempnames->next=NULL;
  1094.         while(j<lcbSttbfffn)
  1095.             {
  1096.             k=0;
  1097.             tempnames->name[0] = '\0';
  1098.             tempnames->next=NULL;
  1099.             len = getc(tablefd);
  1100.             error(erroroutput,"len is %d\n",len);
  1101.             i=1;
  1102.             notfinished=1;
  1103.             while(i<=len)
  1104.                 {
  1105.                 if ((i >= 40) && (notfinished))
  1106.                     {
  1107.                     tempnames->name[k] = read_16ubit(tablefd);
  1108.                     i+=2;
  1109.                     error(erroroutput,"font name char is %X %c %x i is %d\n",tempnames->name[k],tempnames->name[k],ftell(tablefd),i);
  1110.                     if (tempnames->name[k] == 0)
  1111.                         notfinished=0;
  1112.                     k++;
  1113.                     }
  1114.                 else
  1115.                     {    
  1116.                     if (i==4)
  1117.                         {
  1118.                         tempnames->chs = getc(tablefd);
  1119.                         error(erroroutput,"chs is (%x)  %d ",tempnames->chs,tempnames->chs);
  1120.                         }
  1121.                     else
  1122.                         getc(tablefd);
  1123.                     i++;
  1124.                     }
  1125.                 }
  1126.             if (tempnames->name[0] != '\0')
  1127.                 {
  1128.                 tempnames->next = (ffn *) malloc(sizeof(ffn));
  1129.                 if (tempnames->next == NULL)
  1130.                     {
  1131.                     fprintf(erroroutput,"no memory, arrgh\n");
  1132.                     return(-1);
  1133.                     }
  1134.                 tempnames = tempnames->next;
  1135.                 tempnames->next=NULL;
  1136.                 tempnames->name[0] = '\0';
  1137.                 }
  1138.             j+=i;    
  1139.             }
  1140.         }
  1141.  
  1142.     tempnames = &fontnamelist;
  1143.     while (tempnames != NULL)
  1144.         {
  1145.         error(erroroutput,"font names are %s\n",tempnames->name);
  1146.         tempnames = tempnames->next;
  1147.         }
  1148.  
  1149.     /*determine field plc*/
  1150.     fcPlcffldMom=read_32ubit(mainfd);
  1151.     lcbPlcffldMom=read_32ubit(mainfd);
  1152.     error(erroroutput,"in table stream field plc is %ld, and len is %ld\n",fcPlcffldMom,lcbPlcffldMom);
  1153.  
  1154.     main_fields.cps = NULL;
  1155.     main_fields.flds = NULL;
  1156.     main_fields.no = -1;
  1157.  
  1158.     if (lcbPlcffldMom > 0)
  1159.         {
  1160.         error(erroroutput,"guessing that no of entries is %d\n",(lcbPlcffldMom-4)/6);
  1161.         cp_plcfld = (U32 *) malloc( (((lcbPlcffldMom-4)/6)+1) * sizeof(U32));
  1162.         if (cp_plcfld == NULL)
  1163.             {
  1164.             fprintf(erroroutput,"no mem\n");
  1165.             exit(-1);
  1166.             }
  1167.  
  1168.         fld_plcfld = (U8 *) malloc( (((lcbPlcffldMom-4)/6)*2) * sizeof(U8));
  1169.         if ((fld_plcfld == NULL) && (lcbPlcffldMom-4 > 0))
  1170.             {
  1171.             fprintf(erroroutput,"no mem\n");
  1172.             exit(-1);
  1173.             }
  1174.  
  1175.         fseek(tablefd,fcPlcffldMom,SEEK_SET);
  1176.         for(i=0;i<(((lcbPlcffldMom-4)/6)+1);i++)
  1177.             {
  1178.             cp_plcfld[i] =  read_32ubit(tablefd);
  1179.             error(erroroutput,"field cps are %x\n",cp_plcfld[i]);
  1180.             }
  1181.         for(i=0;i<(((lcbPlcffldMom-4)/6)*2);i++)
  1182.             {
  1183.             fld_plcfld[i] =  getc(tablefd);
  1184.             error(erroroutput,"field vals are %d\n",fld_plcfld[i]);
  1185.             }
  1186.  
  1187.         main_fields.cps = cp_plcfld;
  1188.         main_fields.flds = fld_plcfld;
  1189.         main_fields.no = (lcbPlcffldMom-4)/6;
  1190.         }
  1191.  
  1192.     fcPlcffldHdr=read_32ubit(mainfd);
  1193.     lcbPlcffldHdr=read_32ubit(mainfd);
  1194.     error(erroroutput,"in table stream field header plc is (%x), and len is %ld\n",fcPlcffldHdr,lcbPlcffldHdr);
  1195.  
  1196.     header_fields.cps = NULL;
  1197.     header_fields.flds = NULL;
  1198.     header_fields.no = -1;
  1199.  
  1200.     if (lcbPlcffldHdr> 0)
  1201.         {
  1202.         error(erroroutput,"guessing that no of entries is %d\n",(lcbPlcffldHdr-4)/6);
  1203.         cp_plcfld2 = (U32 *) malloc( (((lcbPlcffldHdr-4)/6)+1) * sizeof(U32));
  1204.         if (cp_plcfld2 == NULL)
  1205.             {
  1206.             fprintf(erroroutput,"no mem\n");
  1207.             exit(-1);
  1208.             }
  1209.  
  1210.         fld_plcfld2 = (U8 *) malloc( (((lcbPlcffldHdr-4)/6)*2) * sizeof(U8));
  1211.         if ((fld_plcfld2 == NULL) && (lcbPlcffldHdr-4 > 0))
  1212.             {
  1213.             fprintf(erroroutput,"no mem\n");
  1214.             exit(-1);
  1215.             }
  1216.  
  1217.         fseek(tablefd,fcPlcffldHdr,SEEK_SET);
  1218.         for(i=0;i<(((lcbPlcffldHdr-4)/6)+1);i++)
  1219.             {
  1220.             cp_plcfld2[i] =  read_32ubit(tablefd);
  1221.             error(erroroutput,"header field cps are %x\n",cp_plcfld2[i]);
  1222.             }
  1223.         for(i=0;i<(((lcbPlcffldHdr-4)/6)*2);i++)
  1224.             {
  1225.             fld_plcfld2[i] =  getc(tablefd);
  1226.             error(erroroutput,"field vals are %d\n",fld_plcfld2[i]);
  1227.             }
  1228.  
  1229.         header_fields.cps = cp_plcfld2;
  1230.         header_fields.flds = fld_plcfld2;
  1231.         header_fields.no = (lcbPlcffldHdr-4)/6;
  1232.         }
  1233.  
  1234.     fcPlcffldFtn=read_32ubit(mainfd);
  1235.     lcbPlcffldFtn=read_32ubit(mainfd);
  1236.     error(erroroutput,"in table stream field footnote plc is (%x), and len is %ld\n",fcPlcffldFtn,lcbPlcffldFtn);
  1237.     fcPlcffldAtn=read_32ubit(mainfd);
  1238.     lcbPlcffldAtn=read_32ubit(mainfd);
  1239.     error(erroroutput,"in table stream field annotation plc is (%x), and len is %ld\n",fcPlcffldAtn,lcbPlcffldAtn);
  1240.  
  1241.     footnote_fields.cps = NULL;
  1242.     footnote_fields.flds = NULL;
  1243.     footnote_fields.no = -1;
  1244.  
  1245.     if (lcbPlcffldFtn >0)
  1246.         {
  1247.         error(erroroutput,"guessing that no of entries is %d\n",(lcbPlcffldFtn-4)/6);
  1248.         cp_plcfld3 = (U32 *) malloc( (((lcbPlcffldFtn-4)/6)+1) * sizeof(U32));
  1249.         if (cp_plcfld3 == NULL)
  1250.             {
  1251.             fprintf(erroroutput,"no mem\n");
  1252.             exit(-1);
  1253.             }
  1254.  
  1255.         fld_plcfld3 = (U8 *) malloc( (((lcbPlcffldFtn-4)/6)*2) * sizeof(U8));
  1256.         if ((fld_plcfld3 == NULL) && (lcbPlcffldFtn-4 > 0))
  1257.             {
  1258.             fprintf(erroroutput,"no mem\n");
  1259.             exit(-1);
  1260.             }
  1261.  
  1262.         fseek(tablefd,fcPlcffldFtn,SEEK_SET);
  1263.         for(i=0;i<(((lcbPlcffldFtn-4)/6)+1);i++)
  1264.             {
  1265.             cp_plcfld3[i] =  read_32ubit(tablefd);
  1266.             error(erroroutput,"footnote field cps are %x\n",cp_plcfld3[i]);
  1267.             }
  1268.         for(i=0;i<(((lcbPlcffldFtn-4)/6)*2);i++)
  1269.             {
  1270.             fld_plcfld3[i] =  getc(tablefd);
  1271.             error(erroroutput,"field vals are %d\n",fld_plcfld3[i]);
  1272.             }
  1273.  
  1274.         footnote_fields.cps = cp_plcfld3;
  1275.         footnote_fields.flds = fld_plcfld3;
  1276.         footnote_fields.no = (lcbPlcffldFtn-4)/6;
  1277.         }
  1278.  
  1279.     annotation_fields.cps = NULL;
  1280.     annotation_fields.flds = NULL;
  1281.     annotation_fields.no = -1;
  1282.  
  1283.     if (lcbPlcffldAtn>0)
  1284.         {
  1285.         error(erroroutput,"guessing that no of entries is %d\n",(lcbPlcffldAtn-4)/6);
  1286.         cp_plcfld4 = (U32 *) malloc( (((lcbPlcffldAtn-4)/6)+1) * sizeof(U32));
  1287.         if (cp_plcfld4 == NULL)
  1288.             {
  1289.             fprintf(erroroutput,"no mem\n");
  1290.             exit(-1);
  1291.             }
  1292.  
  1293.         fld_plcfld4 = (U8 *) malloc( (((lcbPlcffldAtn-4)/6)*2) * sizeof(U8));
  1294.         if ((fld_plcfld4 == NULL) && (lcbPlcffldAtn-4 > 0))
  1295.             {
  1296.             fprintf(erroroutput,"no mem\n");
  1297.             exit(-1);
  1298.             }
  1299.  
  1300.         fseek(tablefd,fcPlcffldAtn,SEEK_SET);
  1301.         for(i=0;i<(((lcbPlcffldAtn-4)/6)+1);i++)
  1302.             {
  1303.             cp_plcfld4[i] =  read_32ubit(tablefd);
  1304.             error(erroroutput,"annotation field cps are %x\n",cp_plcfld4[i]);
  1305.             }
  1306.         for(i=0;i<(((lcbPlcffldAtn-4)/6)*2);i++)
  1307.             {
  1308.             fld_plcfld4[i] =  getc(tablefd);
  1309.             error(erroroutput,"field vals are %d\n",fld_plcfld4[i]);
  1310.             }
  1311.  
  1312.         annotation_fields.cps = cp_plcfld4;
  1313.         annotation_fields.flds = fld_plcfld4;
  1314.         annotation_fields.no = (lcbPlcffldAtn-4)/6;
  1315.         }
  1316.  
  1317.  
  1318.     decode_bookmarks(mainfd,tablefd,&portions);
  1319.  
  1320.  
  1321.     /*complex info bit*/
  1322.     fseek(mainfd,418,SEEK_SET);
  1323.     fcClx =  read_32ubit(mainfd);
  1324.     lcbClx = read_32ubit(mainfd);
  1325.     error(erroroutput,"complex bit begins at %X, and it %d long",fcClx,lcbClx);
  1326.  
  1327.     fseek(mainfd,442,SEEK_SET);
  1328.     fcGrpXstAtnOwners = read_32ubit(mainfd);
  1329.     lcbGrpXstAtnOwners = read_32ubit(mainfd);
  1330.     error(erroroutput,"fcGrpXstAtnOwners %x, lcbGrpXstAtnOwners %d\n",fcGrpXstAtnOwners,lcbGrpXstAtnOwners);
  1331.     portions.authors = extract_authors(tablefd,fcGrpXstAtnOwners,lcbGrpXstAtnOwners);
  1332.     decode_annotations(mainfd,tablefd,&portions);
  1333.  
  1334.     fseek(mainfd,474,SEEK_SET);
  1335.     fcPlcspaMom = read_32ubit(mainfd);
  1336.     lcbPlcspaMom = read_32ubit(mainfd);
  1337.     error(erroroutput,"error: pictures offset %x len %d\n",fcPlcspaMom,lcbPlcspaMom);
  1338.  
  1339.     portions.noofficedraw=0;
  1340.     portions.officedrawcps=NULL;
  1341.     portions.spids=NULL;
  1342.     portions.noofblipdata=0;
  1343.  
  1344.     if (lcbPlcspaMom!=0)
  1345.         {
  1346.         fseek(tablefd,fcPlcspaMom,SEEK_SET);
  1347.         portions.noofficedraw = (lcbPlcspaMom-4)/28;
  1348.         portions.officedrawcps = (U32 *) malloc(sizeof(U32) * (portions.noofficedraw+1));
  1349.         portions.spids=(U32 *) malloc(sizeof(U32) * portions.noofficedraw);
  1350.         if ((portions.officedrawcps == NULL) || ((portions.spids == NULL) && (portions.noofficedraw >0)) )
  1351.             {
  1352.             error(erroroutput,"no mem for spids\n");
  1353.             return(-1);
  1354.             }
  1355.         for(i=0;i<portions.noofficedraw+1;i++)
  1356.             {
  1357.             portions.officedrawcps[i] = read_32ubit(tablefd);
  1358.             error(erroroutput,"office draw cp is %x\n",portions.officedrawcps[i]);
  1359.             }
  1360.         for(i=0;i<portions.noofficedraw;i++)
  1361.             {
  1362.             portions.spids[i] = read_32ubit(tablefd);
  1363.             error(erroroutput,"spid id %x\n",portions.spids[i]);
  1364.             for (j=0;j<22;j++)
  1365.                 getc(tablefd);
  1366.             }
  1367.         }
  1368.  
  1369.     /*begin endnote*/
  1370.     fseek(mainfd,522,SEEK_SET);
  1371.     fcPlcfendRef = read_32ubit(mainfd);
  1372.     lcbPlcfendRef = read_32ubit(mainfd);
  1373.     fcPlcfendTxt = read_32ubit(mainfd);
  1374.     lcbPlcfendTxt = read_32ubit(mainfd);
  1375.  
  1376.     error(erroroutput,"endnote: table offset of frd thingies (%x) of len %d\n",fcPlcfendRef,lcbPlcfendRef);
  1377.     error(erroroutput,"endnote: table offset for endnote text (%x) of len %d\n",fcPlcfendTxt,lcbPlcfendTxt);
  1378.  
  1379.     portions.endRef=NULL;
  1380.     portions.endFRD=NULL;
  1381.     portions.endTrueFRD=NULL;
  1382.     portions.endTxt=NULL;
  1383.     portions.list_end_no = 0;
  1384.     portions.auto_end=1;
  1385.  
  1386.     portions.endref_no=0;
  1387.     portions.endtxt_no=0;
  1388.  
  1389.     if (lcbPlcfendRef != 0)
  1390.         {
  1391.         portions.endref_no=(lcbPlcfendRef-4)/6;
  1392.         portions.endRef = (U32 *) malloc( (portions.endref_no+1) * sizeof(U32));
  1393.         if (portions.endRef == NULL)
  1394.             {
  1395.             fprintf(erroroutput,"NO MEM 1\n");
  1396.             return(-1);
  1397.             }
  1398.  
  1399.         portions.endFRD = (S16 *) malloc( portions.endref_no * sizeof(S16));
  1400.         portions.endTrueFRD = (S16 *) malloc( portions.endref_no * sizeof(S16));
  1401.         if ((portions.endFRD == NULL) || (portions.endTrueFRD == NULL))
  1402.             {
  1403.             fprintf(erroroutput,"NO MEM 2\n");
  1404.             return(-1);
  1405.             }
  1406.         fseek(tablefd,fcPlcfendRef,SEEK_SET);
  1407.         for(i=0;i<portions.endref_no+1;i++)
  1408.             {
  1409.             portions.endRef[i]=read_32ubit(tablefd);
  1410.             error(erroroutput,"endRef is %x\n",portions.endRef[i]);
  1411.             }
  1412.         for(i=0;i<portions.endref_no;i++)
  1413.             {
  1414.             portions.endFRD[i]=(S16)read_16ubit(tablefd);
  1415.             portions.endTrueFRD[i]=portions.endFRD[i];
  1416.             error(erroroutput,"endFRD is %d\n",portions.endFRD[i]);
  1417.             }
  1418.         }
  1419.  
  1420.     if (lcbPlcfendTxt!= 0)
  1421.         {
  1422.         portions.endtxt_no=lcbPlcfendTxt/4;
  1423.         portions.endTxt = (U32 *) malloc( portions.endtxt_no  * sizeof(U32) );
  1424.         if (portions.endTxt == NULL)
  1425.             {
  1426.             fprintf(erroroutput,"NO MEM 3\n");
  1427.             return(-1);
  1428.             }
  1429.         fseek(tablefd,fcPlcfendTxt,SEEK_SET);
  1430.         for (i=0;i<portions.endtxt_no;i++)
  1431.             {
  1432.             portions.endTxt[i]=read_32ubit(tablefd);
  1433.             error(erroroutput,"footnote->%x\n",portions.endTxt[i]);
  1434.             }
  1435.         }
  1436.  
  1437.     fcPlcffldEdn = read_32ubit(mainfd);
  1438.     lcbPlcffldEdn = read_32ubit(mainfd);
  1439.  
  1440.  
  1441.     endnote_fields.cps = NULL;
  1442.     endnote_fields.flds = NULL;
  1443.     endnote_fields.no = -1;
  1444.  
  1445.     if (lcbPlcffldEdn>0)
  1446.         {
  1447.         error(erroroutput,"guessing that no of entries is %d\n",(lcbPlcffldEdn-4)/6);
  1448.         cp_plcfld5 = (U32 *) malloc( (((lcbPlcffldEdn-4)/6)+1) * sizeof(U32));
  1449.         if (cp_plcfld5 == NULL)
  1450.             {
  1451.             fprintf(erroroutput,"no mem\n");
  1452.             exit(-1);
  1453.             }
  1454.  
  1455.         fld_plcfld5 = (U8 *) malloc( (((lcbPlcffldEdn-4)/6)*2) * sizeof(U8));
  1456.         if ((fld_plcfld5 == NULL) && (lcbPlcffldEdn-4 > 0))
  1457.             {
  1458.             fprintf(erroroutput,"no mem\n");
  1459.             exit(-1);
  1460.             }
  1461.  
  1462.         fseek(tablefd,fcPlcffldEdn,SEEK_SET);
  1463.         for(i=0;i<(((lcbPlcffldEdn-4)/6)+1);i++)
  1464.             {
  1465.             cp_plcfld5[i] =  read_32ubit(tablefd);
  1466.             error(erroroutput,"endnote field cps are %x\n",cp_plcfld5[i]);
  1467.             }
  1468.         for(i=0;i<(((lcbPlcffldEdn-4)/6)*2);i++)
  1469.             {
  1470.             fld_plcfld5[i] =  getc(tablefd);
  1471.             error(erroroutput,"field vals are %d\n",fld_plcfld5[i]);
  1472.             }
  1473.  
  1474.         endnote_fields.cps = cp_plcfld5;
  1475.         endnote_fields.flds = fld_plcfld5;
  1476.         endnote_fields.no = (lcbPlcffldEdn-4)/6;
  1477.         }
  1478.  
  1479.     /*end endnote*/
  1480.  
  1481.     all_fields[0] = &main_fields;
  1482.     all_fields[1] = &header_fields;
  1483.     all_fields[2] = &footnote_fields;
  1484.     all_fields[3] = &annotation_fields;
  1485.     all_fields[4] = &endnote_fields;
  1486.     
  1487.  
  1488.     fseek(mainfd,554,SEEK_SET);
  1489.     fcDggInfo = read_32ubit(mainfd);
  1490.     lcbDggInfo = read_32ubit(mainfd);
  1491.     error(erroroutput,"fcDggInfo is %x and len is %d\n",fcDggInfo,lcbDggInfo);
  1492.  
  1493.     portions.ablipdata = get_blips(fcDggInfo,lcbDggInfo,tablefd,mainfd,&(portions.noofblipdata),0x08,NULL);
  1494.  
  1495.     fseek(mainfd,730,SEEK_SET);
  1496.     fcSttbFnm =  read_32ubit(mainfd);
  1497.     lcbSttbFnm = read_32ubit(mainfd);
  1498.     fcPlcfLst =  read_32ubit(mainfd);
  1499.     lcbPlcfLst = read_32ubit(mainfd);
  1500.     fcPlfLfo =  read_32ubit(mainfd);
  1501.     lcbPlfLfo = read_32ubit(mainfd);
  1502.  
  1503.     get_table_info(tablefd,&a_list_info,fcSttbFnm,lcbSttbFnm,fcPlcfLst,lcbPlcfLst,fcPlfLfo,lcbPlfLfo,masterstylesheet);
  1504.  
  1505.     error(erroroutput,"\n-----text------ %x\n",1024);
  1506.     if (core)
  1507.         fprintf(outputfile,"<html>\n");
  1508.     fseek(mainfd,1024,SEEK_SET);
  1509.  
  1510.     error(erroroutput,"endpoint for standard is %ld\n",fcMac);
  1511.  
  1512.  
  1513.     fseek(tablefd,portions.fcPlcfhdd,SEEK_SET);
  1514.     portions.headercpno = portions.lcbPlcfhdd/4;
  1515.     portions.headercplist = NULL;
  1516.     if (portions.headercpno > 0)
  1517.         {
  1518.         error(erroroutput,"head no is %d\n",portions.headercpno);
  1519.         portions.headercplist = malloc(sizeof(U32) * portions.headercpno);
  1520.         if (portions.headercplist == NULL)
  1521.             {
  1522.             error(erroroutput,"feck no mem\n");
  1523.             return(-1);
  1524.             }
  1525.  
  1526.         for (i=0;i<portions.headercpno;i++)
  1527.             {
  1528.             portions.headercplist[i]= read_32ubit(tablefd);
  1529.             error(erroroutput,"header fc ? is %x -> %x  %d",portions.headercplist[i],portions.fcMin+portions.ccpText+portions.ccpFtn+portions.headercplist[i],i);
  1530.             switch (i)
  1531.                 {
  1532.                 case 6:
  1533.                     error(erroroutput,"even header\n");
  1534.                     break;
  1535.                 case 7:
  1536.                     error(erroroutput,"odd header\n");
  1537.                     break;
  1538.                 case 8:
  1539.                     error(erroroutput,"even footer\n");
  1540.                     break;
  1541.                 case 9:
  1542.                     error(erroroutput,"odd footer\n");
  1543.                     break;
  1544.                 case 10:
  1545.                     error(erroroutput,"page 1 special header\n");
  1546.                     break;
  1547.                 case 11:
  1548.                     error(erroroutput,"page 1 special footer\n");
  1549.                     break;
  1550.                 case 12:
  1551.                     error(erroroutput,"even header, section 2?\n");
  1552.                     break;
  1553.                 case 13:
  1554.                     error(erroroutput,"odd header, section 2?\n");
  1555.                     break;
  1556.                 default:
  1557.                     error(erroroutput,"\n");
  1558.                     break;
  1559.                 }
  1560.             }
  1561.         }
  1562.  
  1563.     if (iscomplex)
  1564.         {
  1565.         error(erroroutput,"complex writing complex table looking in %ld (len %ld)\n",fcClx,lcbClx);
  1566.         /*i believe that the intervals and plcfbtePapx are valid entities for
  1567.         fastsaved docs as well (i bloody hope so)*/
  1568.         fprintf(outputfile,"<!--complex document-->\n");
  1569.         error(erroroutput,"main ends at %x\n",portions.ccpText);
  1570.         decode_clx(0,0,portions.ccpText,tablefd,mainfd,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,&a_list_info,masterstylesheet,&portions,&fontnamelist,0);
  1571.         }
  1572.     else
  1573.         {
  1574.         error(erroroutput,"decoding simple\n");
  1575.         fprintf(outputfile,"<!--noncomplex document-->\n");
  1576.  
  1577.             
  1578.         decode_simple(mainfd,tablefd,data,fcClx,fcMin,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,&a_list_info,masterstylesheet,&portions,&fontnamelist,0);
  1579.         }
  1580.  
  1581.  
  1582.     if ( (list_author_key) && (key_atrd!=NULL) )
  1583.         {
  1584.         fprintf(outputfile,"<p>\n");
  1585.         fprintf(outputfile,"<table border=1>\n");
  1586.         fprintf(outputfile,"<tr><td colspan=2><b>Annotation Author Key</b></td></tr>");
  1587.         fprintf(outputfile,"<tr><td>Initials</td><td>Full Name</td></tr>");
  1588.  
  1589.         for (i=0;i<portions.authors->noofstrings;i++)
  1590.             {
  1591.             fprintf(outputfile,"<tr><td>");
  1592.  
  1593.             j = key_atrd[i].xstUsrInitl[0];
  1594.               for (j=1;j<key_atrd[i].xstUsrInitl[0]+1;j++)
  1595.                     {
  1596.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  1597.                     fprintf(outputfile,"%c",key_atrd[i].xstUsrInitl[j]);
  1598.                     }
  1599.             j = 0;
  1600.             fprintf(outputfile,"</td><td>");
  1601.             freegroup = portions.authors;
  1602.             while ((j<key_atrd[i].ibst) && (freegroup != NULL))
  1603.                 {
  1604.                 freegroup = freegroup->next;
  1605.                 j++;
  1606.                 }
  1607.             k=0;    
  1608.  
  1609.             if (freegroup->author != NULL)
  1610.                 {
  1611.                 while(freegroup->author[k] != '\0')
  1612.                         {
  1613.                         /*warning despite the possibility of being 16 bit nos ive done this*/
  1614.                         fprintf(outputfile,"%c",freegroup->author[k]);
  1615.                         k++;
  1616.                         }
  1617.                 }
  1618.             fprintf(outputfile,"</td></tr>");
  1619.             }
  1620.         fprintf(outputfile,"</table>\n");
  1621.         }
  1622.  
  1623.  
  1624.     if (main_fields.cps != NULL)
  1625.         free(main_fields.cps);
  1626.     if (main_fields.flds != NULL)
  1627.         free(main_fields.flds);
  1628.     if (header_fields.cps != NULL)
  1629.         free(header_fields.cps);
  1630.     if (header_fields.flds != NULL)
  1631.         free(header_fields.flds);
  1632.     if (footnote_fields.cps != NULL)
  1633.         free(footnote_fields.cps);
  1634.     if (footnote_fields.flds != NULL)
  1635.         free(footnote_fields.flds);
  1636.     if (annotation_fields.cps != NULL)
  1637.         free(annotation_fields.cps);
  1638.     if (annotation_fields.flds != NULL)
  1639.         free(annotation_fields.flds);
  1640.     if (endnote_fields.cps != NULL)
  1641.         free(endnote_fields.cps);
  1642.     if (endnote_fields.flds != NULL)
  1643.         free(endnote_fields.flds);
  1644.  
  1645.  
  1646.  
  1647.  
  1648.     if (a_list_info.array != NULL)
  1649.         free(a_list_info.array);
  1650.     if (a_list_info.o_lst_ids != NULL)
  1651.         free(a_list_info.o_lst_ids);
  1652.     if (a_list_info.level != NULL)
  1653.         free(a_list_info.level);
  1654.     if (a_list_info.lstarray != NULL)
  1655.         free(a_list_info.lstarray);
  1656.     if (a_list_info.lst_ids != NULL)
  1657.         free(a_list_info.lst_ids);
  1658.  
  1659.     if (a_list_info.current_index_nos != NULL)
  1660.         {
  1661.         for (i=0;i<a_list_info.nooflsts+1;i++)
  1662.             free(a_list_info.current_index_nos[i]);
  1663.         free(a_list_info.current_index_nos);
  1664.         }
  1665.  
  1666.     if (a_list_info.o_list_def != NULL)
  1667.         {
  1668.         for (i=0;i<a_list_info.nooflfos;i++)
  1669.             {
  1670.             if (a_list_info.overridecount[i] > 0)
  1671.                 {
  1672.                 free_def = &(a_list_info.o_list_def[i]);
  1673.                 if (free_def->list_string != NULL)
  1674.                     free(free_def->list_string);
  1675.                 free_def = free_def->sub_def_list;
  1676.                 while (free_def != NULL)
  1677.                     {
  1678.                     free_def2 = free_def;
  1679.                     free_def = free_def->sub_def_list;
  1680.                     if (free_def2->list_string != NULL)
  1681.                         free(free_def2->list_string);
  1682.                     free(free_def2);
  1683.                     }
  1684.                 }
  1685.             }
  1686.         free(a_list_info.o_list_def);
  1687.         }       
  1688.  
  1689.     if (a_list_info.overridecount != NULL)
  1690.         free(a_list_info.overridecount);
  1691.  
  1692.     if (a_list_info.a_list_def != NULL)
  1693.         {
  1694.         for (i=0;i<a_list_info.nooflsts;i++)
  1695.             {
  1696.             free_def = &(a_list_info.a_list_def[i]);
  1697.             if (free_def->list_string != NULL)
  1698.                 free(free_def->list_string);
  1699.             free_def = free_def->sub_def_list;
  1700.             while (free_def != NULL)
  1701.                 {
  1702.                 free_def2 = free_def;
  1703.                 free_def = free_def->sub_def_list;
  1704.                 if (free_def2->list_string != NULL)
  1705.                     free(free_def2->list_string);
  1706.                 free(free_def2);
  1707.                 }
  1708.             }
  1709.         free(a_list_info.a_list_def);
  1710.         }
  1711.  
  1712.     
  1713.     if (masterstylesheet != NULL)
  1714.         free(masterstylesheet);
  1715.     
  1716.      tempnames = &fontnamelist;
  1717.     tempnames = tempnames->next;
  1718.     while (tempnames != NULL)
  1719.         {
  1720.         freenames = tempnames;
  1721.         tempnames = tempnames->next;
  1722.         free(freenames);
  1723.         }
  1724.  
  1725.     free(plcfbtePapx);
  1726.     free(plcfbteChpx);
  1727.  
  1728.     while (portions.authors != NULL)
  1729.         {
  1730.         freegroup = portions.authors;
  1731.         portions.authors= portions.authors->next;
  1732.         if (freegroup->author!= NULL)
  1733.             free(freegroup->author);
  1734.         free(freegroup);
  1735.         }
  1736.  
  1737.     while (portions.ablipdata != NULL)
  1738.         {
  1739.         freeme = portions.ablipdata;
  1740.         portions.ablipdata = portions.ablipdata->next;
  1741.         free(freeme);
  1742.         }
  1743.     if (portions.endRef!=NULL)
  1744.         free(portions.endRef);
  1745.     if (portions.endFRD!=NULL)
  1746.         free(portions.endFRD);
  1747.     if (portions.endTrueFRD!=NULL)
  1748.         free(portions.endTrueFRD);
  1749.     if (portions.endTxt!=NULL)
  1750.         free(portions.endTxt);
  1751.     if (portions.fndRef != NULL)
  1752.         free(portions.fndRef);
  1753.     if (portions.fndFRD!=NULL);
  1754.         free(portions.fndFRD);
  1755.     if (portions.fndTrueFRD!=NULL);
  1756.         free(portions.fndTrueFRD);
  1757.     if (portions.fndTxt!=NULL);
  1758.         free(portions.fndTxt);
  1759.  
  1760.     if (portions.andTxt != NULL)
  1761.         free(portions.andTxt);
  1762.     if (portions.andRef != NULL)
  1763.         free(portions.andRef);
  1764.     if (portions.the_atrd != NULL)
  1765.         free(portions.the_atrd);
  1766.     
  1767.  
  1768.     if (portions.annotations.extra_bytes!=NULL)
  1769.         {
  1770.         for (i=0;i<portions.annotations.no_of_strings;i++)
  1771.             free(portions.annotations.extra_bytes[i]);
  1772.         free(portions.annotations.extra_bytes);
  1773.         }
  1774.     if (portions.a_bookmarks.bookmark_b_cps!=NULL)
  1775.         free(portions.a_bookmarks.bookmark_b_cps);
  1776.     if (portions.a_bookmarks.bookmark_b_bkfs!=NULL)
  1777.         free(portions.a_bookmarks.bookmark_b_bkfs);
  1778.     if (portions.a_bookmarks.bookmark_e_cps!=NULL)
  1779.         free(portions.a_bookmarks.bookmark_e_cps);
  1780.     if (portions.annotations.chars!=NULL)
  1781.         {
  1782.         for (i=0;i<portions.annotations.no_of_strings;i++)
  1783.             free(portions.annotations.chars[i]);
  1784.         free(portions.annotations.chars);
  1785.         }
  1786.  
  1787.         
  1788.     if (portions.headercplist != NULL)
  1789.         free(portions.headercplist);
  1790.     if (portions.officedrawcps != NULL)
  1791.         free(portions.officedrawcps);
  1792.     if (portions.spids != NULL)
  1793.         free(portions.spids);
  1794.     if (portions.section_cps != NULL)
  1795.         free(portions.section_cps);
  1796.     if (portions.section_fcs != NULL)
  1797.         free(portions.section_fcs);
  1798.  
  1799.     if (portions.l_bookmarks.bookmark_b_cps!=NULL)
  1800.         free(portions.l_bookmarks.bookmark_b_cps);
  1801.     if (portions.l_bookmarks.bookmark_b_bkfs!=NULL)
  1802.         free(portions.l_bookmarks.bookmark_b_bkfs);
  1803.     if (portions.l_bookmarks.bookmark_e_cps!=NULL)
  1804.         free(portions.l_bookmarks.bookmark_e_cps);
  1805.     if (portions.bookmarks.extra_bytes!=NULL)
  1806.         {
  1807.         for (i=0;i<portions.bookmarks.no_of_strings;i++)
  1808.             free(portions.bookmarks.extra_bytes[i]);
  1809.         free(portions.bookmarks.extra_bytes);
  1810.         }
  1811.     if (portions.bookmarks.chars!=NULL)
  1812.         {
  1813.         for (i=0;i<portions.bookmarks.no_of_strings;i++)
  1814.             free(portions.bookmarks.chars[i]);
  1815.         free(portions.bookmarks.chars);
  1816.         }
  1817.     return(0);
  1818.     }
  1819.  
  1820. U32 get_fc_from_cp(U32 acp,U32 *rgfc,U32 *avalrgfc,int nopieces)
  1821.     {
  1822.     int i=0;
  1823.     U32 distance;
  1824.     U32 fc2;
  1825.  
  1826.     /*given a cp find the piece*/
  1827.     while(i<nopieces)
  1828.         {
  1829.         if (rgfc[i+1] >= acp)
  1830.             {
  1831.             distance = acp-rgfc[i];    
  1832.             error(erroroutput,"cp distance is %d\n",distance);
  1833.             if (avalrgfc[i] & 0x40000000UL)
  1834.                 {
  1835.                 fc2 = avalrgfc[i];
  1836.                 fc2 = fc2 & 0xbfffffffUL;
  1837.                 fc2 = fc2/2;
  1838.                 return(fc2+distance);
  1839.                 }
  1840.             else
  1841.                 return(avalrgfc[i]+(2*distance));
  1842.             }
  1843.         i++;
  1844.         }
  1845.     return(0);
  1846.     }
  1847.  
  1848. int decode_simple_endnote(FILE *mainfd,FILE *tablefd,FILE *data,sep *asep,U32 fcClx,U32 fcMin,U32 fcMac,U32 intervals,U32 chpintervals,U32 *plcfbtePapx,U32 *plcfbteChpx,field_info *all_fields[4],list_info *a_list_info,style *sheet,textportions *portions,ffn *fontnamelist,int flag)
  1849.     {
  1850.     U32 headerpos;
  1851.     U32 oldccpText;
  1852.     U32 begin=0;
  1853.     U32 len=0;
  1854.     int tempcp;
  1855.     int i;
  1856.     
  1857.     field_info *tempfields;
  1858.     chp achp;
  1859.     int nopieces;
  1860.     U32 *avalrgfc;
  1861.     U32 *rgfc;
  1862.     U16 *sprm;
  1863.     U32 clxcount=0;
  1864.     U32 fcvalue;
  1865.     pap indentpap;
  1866.     int anyendnotes=0;
  1867.     char roman[81];
  1868.     
  1869.     flushbreaks(0);
  1870.     init_pap(&indentpap);
  1871.     do_indent(&indentpap);
  1872.  
  1873.     if (noheaders)
  1874.         return(0);
  1875.  
  1876.     if (header == 0)
  1877.         {
  1878.         error(erroroutput,"doing endnotes page number is %d\n",pagenumber);
  1879.  
  1880.         for (i=0;i<portions->list_end_no;i++)
  1881.             {
  1882.             decode_endnote(&begin,&len,portions,i);
  1883.  
  1884.             if ((begin != -1) && (len != -1))
  1885.                 {
  1886.                 if (anyendnotes==0)
  1887.                     fprintf(outputfile,"\n<br><img src=\"%s/endnotebegin.gif\"><br>\n",patterndir());
  1888.                 anyendnotes=1;
  1889.                 init_chp(&achp);
  1890.                 decode_s_chp(&achp,fontnamelist);
  1891.                 error(erroroutput,"beginning endnote\n");
  1892.                 fprintf(outputfile,"<p>");
  1893.                 /*test*/
  1894.                 fprintf(outputfile,"<font color=#330099>");
  1895.                 inafont=1;
  1896.                 inacolor=1;
  1897.                 strcpy(incolor,"#330099");
  1898.                 /*end test*/
  1899.                 if (!insuper)
  1900.                     {
  1901.                     fprintf(outputfile,"<sup>");
  1902.                     insuper=2;
  1903.                     }
  1904.                 fprintf(outputfile,"<a name=\"end%d\">",i);
  1905.  
  1906.                 if (portions->endFRD[i] > 0)
  1907.                     {
  1908.                     error(erroroutput,"FRD is %d, end is %d, i is %d\n",portions->endTrueFRD[i],portions->auto_end,i);
  1909.                     fprintf(outputfile,"%s",ms_strlower(decimalToRoman(portions->endTrueFRD[i],roman)));
  1910.                     fprintf(outputfile,"</A>");
  1911.                     if (insuper==2)
  1912.                         {
  1913.                         fprintf(outputfile,"</sup>");
  1914.                         insuper=0;
  1915.                         }
  1916.                     }
  1917.                 else
  1918.                     footnotehack=1;
  1919.                     
  1920.                 /*dont handling custom footnotes this way*/
  1921.  
  1922.                 headerpos = ftell(mainfd);
  1923.                 oldccpText = portions->ccpText;
  1924.                 header++;
  1925.  
  1926.                 fseek(tablefd,fcClx,SEEK_SET);
  1927.                 getc(tablefd);
  1928.                 nopieces = get_piecetable(tablefd,&rgfc,&avalrgfc,&sprm,&clxcount);
  1929.                 
  1930.                 fcvalue = get_fc_from_cp(oldccpText+portions->ccpFtn+portions->ccpHdd+portions->ccpAtn+begin,rgfc,avalrgfc,nopieces);
  1931.  
  1932.                 free(rgfc);
  1933.                 free(avalrgfc);
  1934.                 free(sprm);
  1935.                 error(erroroutput,"footer fcvalue is %x, old one would be %x\n",fcvalue,portions->fcMin+oldccpText+begin);
  1936.                 tempcp=cp;
  1937.                 portions->ccpText = len;
  1938.                 cp=begin;
  1939.                 tempfields = all_fields[0];
  1940.                 all_fields[0] = all_fields[4];
  1941.                 realcp = oldccpText+portions->ccpFtn+portions->ccpHdd+portions->ccpAtn;
  1942.                 inaheaderfooter=1;
  1943.                 /*temp line*/
  1944.                 fseek(mainfd,fcvalue,SEEK_SET);
  1945.                 decode_simple(mainfd,tablefd,data,fcClx,fcvalue,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,2);
  1946.                 inaheaderfooter=0;
  1947.                 if (footnotehack == 1)
  1948.                     {
  1949.                     fprintf(outputfile,"</A>");
  1950.                     footnotehack=0;
  1951.                     }
  1952.                 all_fields[0] = tempfields;
  1953.                 cp=tempcp;
  1954.                 realcp = tempcp;
  1955.                 fseek(mainfd,headerpos,SEEK_SET);
  1956.                 portions->ccpText = oldccpText;
  1957.                 header--;
  1958.                 error(erroroutput,"ending endnote\n");
  1959.                 }
  1960.             }
  1961.         
  1962.         portions->list_end_no=0; /*ready for next section endnotes*/
  1963.         portions->auto_end=1;
  1964.  
  1965.         
  1966.         
  1967.         init_chp(&achp);
  1968.         decode_s_chp(&achp,fontnamelist);
  1969.         }
  1970.     return(anyendnotes);
  1971.     }
  1972.  
  1973.  
  1974. int decode_simple_footer(FILE *mainfd,FILE *tablefd,FILE *data,sep *asep,U32 fcClx,U32 fcMin,U32 fcMac,U32 intervals,U32 chpintervals,U32 *plcfbtePapx,U32 *plcfbteChpx,field_info *all_fields[4],list_info *a_list_info,style *sheet,textportions *portions,ffn *fontnamelist,int flag)
  1975.     {
  1976.     U32 headerpos;
  1977.     U32 oldccpText;
  1978.     U32 begin=0;
  1979.     U32 len=0;
  1980.     int tempcp;
  1981.     int i,j;
  1982.     int footnoteflag=0;
  1983.     int annotationflag=0;
  1984.     field_info *tempfields;
  1985.     chp achp;
  1986.     int nopieces;
  1987.     U32 *avalrgfc;
  1988.     U32 *rgfc;
  1989.     U16 *sprm;
  1990.     U32 clxcount=0;
  1991.     U32 fcvalue;
  1992.     pap indentpap;
  1993.     int ret=0;
  1994.  
  1995.     flushbreaks(0);
  1996.     init_pap(&indentpap);
  1997.     do_indent(&indentpap);
  1998.  
  1999.     if (noheaders)
  2000.         return(ret);
  2001.     
  2002.     if (header == 0)
  2003.         {
  2004.         error(erroroutput,"doing footer page number is %d\n",pagenumber);
  2005.  
  2006.         for (i=portions->last_foot;i<portions->list_foot_no+portions->last_foot;i++)
  2007.             {
  2008.             decode_footnote(&begin,&len,portions,i);
  2009.  
  2010.             if ((begin != -1) && (len != -1))
  2011.                 {
  2012.                 init_chp(&achp);
  2013.                 decode_s_chp(&achp,fontnamelist);
  2014.                 if (footnoteflag == 0)
  2015.                     {
  2016.                     fprintf(outputfile,"\n<br><img src=\"%s/footnotebegin.gif\"><br>\n",patterndir());
  2017.                     footnoteflag=1;
  2018.                     }
  2019.                 error(erroroutput,"beginning footnote\n");
  2020.                 fprintf(outputfile,"<p>");
  2021.                 /*test*/
  2022.                 fprintf(outputfile,"<font color=#330099>");
  2023.                 inafont=1;
  2024.                 inacolor=1;
  2025.                 strcpy(incolor,"#330099");
  2026.                 /*end test*/
  2027.                 if (!insuper)
  2028.                     {
  2029.                     fprintf(outputfile,"<sup>");
  2030.                     insuper=2;
  2031.                     }
  2032.                 fprintf(outputfile,"<a name=\"foot%d\">",i);
  2033.  
  2034.                 if (portions->fndFRD[i] > 0)
  2035.                     {
  2036.                     fprintf(outputfile,"%d",portions->fndFRD[i]);
  2037.                     fprintf(outputfile,"</A>");
  2038.                     if (insuper==2)
  2039.                         {
  2040.                         fprintf(outputfile,"</sup>");
  2041.                         insuper=0;
  2042.                         }
  2043.                     }
  2044.                 else
  2045.                     footnotehack=1;
  2046.                 /*dont handling custom footnotes this way*/
  2047.  
  2048.                 headerpos = ftell(mainfd);
  2049.                 oldccpText = portions->ccpText;
  2050.                 header++;
  2051.  
  2052.                 fseek(tablefd,fcClx,SEEK_SET);
  2053.                 getc(tablefd);
  2054.                 nopieces = get_piecetable(tablefd,&rgfc,&avalrgfc,&sprm,&clxcount);
  2055.                 
  2056.                 fcvalue = get_fc_from_cp(oldccpText+begin,rgfc,avalrgfc,nopieces);
  2057.  
  2058.                 free(rgfc);
  2059.                 free(avalrgfc);
  2060.                 free(sprm);
  2061.                 /*            
  2062.                 fseek(mainfd,portions->fcMin+oldccpText+begin,SEEK_SET);
  2063.                 */
  2064.                 error(erroroutput,"footer fcvalue is %x, old one would be %x\n",fcvalue,portions->fcMin+oldccpText+begin);
  2065.                 tempcp=cp;
  2066.                 portions->ccpText = len;
  2067.                 cp=begin;
  2068.                 tempfields = all_fields[0];
  2069.                 all_fields[0] = all_fields[2];
  2070.                 realcp = oldccpText+begin;
  2071.                 inaheaderfooter=1;
  2072.                 /*temp line*/
  2073.                 fseek(mainfd,fcvalue,SEEK_SET);
  2074.                 decode_simple(mainfd,tablefd,data,fcClx,fcvalue,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,2);
  2075.                 inaheaderfooter=0;
  2076.                 if (footnotehack == 1)
  2077.                     {
  2078.                     fprintf(outputfile,"</A>");
  2079.                     footnotehack=0;
  2080.                     }
  2081.                 all_fields[0] = tempfields;
  2082.                 cp=tempcp;
  2083.                 realcp = tempcp;
  2084.                 fseek(mainfd,headerpos,SEEK_SET);
  2085.                 portions->ccpText = oldccpText;
  2086.                 header--;
  2087.                 error(erroroutput,"ending footnote\n");
  2088.                 }
  2089.             }
  2090.  
  2091.         portions->last_foot+=portions->list_foot_no;
  2092.         portions->list_foot_no=0; /*ready for next page footnotes*/
  2093.         portions->auto_foot=1;
  2094.         if (footnoteflag != 0)
  2095.             {
  2096.             fprintf(outputfile,"\n<br><img src=\"%s/footnoteend.gif\"><br>\n",patterndir());
  2097.             }
  2098.             
  2099.         for (i=portions->last_anno;i<portions->list_anno_no+portions->last_anno;i++)
  2100.             {
  2101.             decode_footanno(&begin,&len,portions,i);
  2102.             
  2103.             init_chp(&achp);
  2104.             decode_s_chp(&achp,fontnamelist);
  2105.  
  2106.             if ((begin != -1) && (len != -1))
  2107.                 {
  2108.                 if (annotationflag == 0)
  2109.                     {
  2110.                     fprintf(outputfile,"\n<br><img src=\"%s/commentbegin.gif\"><br>\n",patterndir());
  2111.                     annotationflag=1;
  2112.                     }
  2113.                 error(erroroutput,"beginning annotation\n");
  2114.                 /*test*/
  2115.                 fprintf(outputfile,"<font color=#ff7777>");
  2116.                 inafont=1;
  2117.                 inacolor=1;
  2118.                 strcpy(incolor,"#ff7777");
  2119.                 /*end test*/
  2120.                 if (!insuper)
  2121.                     fprintf(outputfile,"<sup>");
  2122.                 /*
  2123.                 fprintf(outputfile,"<a name=\"anno%d\">",i);
  2124.                 */
  2125.                 fprintf(outputfile,"<a name=\"");
  2126.                 j = portions->the_atrd[i].xstUsrInitl[0];
  2127.                 for (j=1;j<portions->the_atrd[i].xstUsrInitl[0]+1;j++)
  2128.                     {
  2129.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  2130.                     fprintf(outputfile,"%c",portions->the_atrd[i].xstUsrInitl[j]);
  2131.                     }
  2132.                 fprintf(outputfile,"%d",i);
  2133.                 fprintf(outputfile,"\">");
  2134.                 list_author_key=1;
  2135.                 j = portions->the_atrd[i].xstUsrInitl[0];
  2136.                 for (j=1;j<portions->the_atrd[i].xstUsrInitl[0]+1;j++)
  2137.                     {
  2138.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  2139.                     fprintf(outputfile,"%c",portions->the_atrd[i].xstUsrInitl[j]);
  2140.                     }
  2141.                 fprintf(outputfile,"%d",i+1);
  2142.                 /*
  2143.                 fprintf(outputfile,"anno%d",i);
  2144.                 */
  2145.                 fprintf(outputfile,"</a>");
  2146.                 if (!insuper)
  2147.                     fprintf(outputfile,"</sup>");
  2148.  
  2149.                 headerpos = ftell(mainfd);
  2150.                 oldccpText = portions->ccpText;
  2151.                 header++;
  2152.  
  2153.                 fseek(tablefd,fcClx,SEEK_SET);
  2154.                 getc(tablefd);
  2155.                 nopieces = get_piecetable(tablefd,&rgfc,&avalrgfc,&sprm,&clxcount);
  2156.                 
  2157.                 fcvalue = get_fc_from_cp(oldccpText+portions->ccpFtn+portions->ccpHdd+begin,rgfc,avalrgfc,nopieces);
  2158.  
  2159.                 free(rgfc);
  2160.                 free(avalrgfc);
  2161.                 free(sprm);
  2162.                 fseek(mainfd,fcvalue,SEEK_SET);
  2163.                 tempcp=cp;
  2164.                 portions->ccpText = len;
  2165.                 cp=begin;
  2166.                 tempfields = all_fields[0];
  2167.                 all_fields[0] = all_fields[3];
  2168.                 realcp = oldccpText+portions->ccpFtn+portions->ccpHdd+begin;
  2169.                 decode_simple(mainfd,tablefd,data,fcClx,fcvalue,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,3);
  2170.                 all_fields[0] = tempfields;
  2171.                 cp=tempcp;
  2172.                 realcp = tempcp;
  2173.                 fseek(mainfd,headerpos,SEEK_SET);
  2174.                 portions->ccpText = oldccpText;
  2175.                 header--;
  2176.                 error(erroroutput,"ending annotation\n");
  2177.                 }
  2178.             }
  2179.  
  2180.         if (annotationflag)
  2181.             fprintf(outputfile,"\n<br><img src=\"%s/commentend.gif\"><br>\n",patterndir());
  2182.             
  2183.         portions->last_anno+=portions->list_anno_no;
  2184.         portions->list_anno_no=0; /*ready for next page footnotes*/
  2185.         
  2186.         decode_footer(&begin,&len,portions,asep);
  2187.         if ((begin != -1) && (len != -1))
  2188.             {
  2189.             init_chp(&achp);
  2190.             decode_s_chp(&achp,fontnamelist);
  2191.             headerpos = ftell(mainfd);
  2192.             oldccpText = portions->ccpText;
  2193.             header++;
  2194.  
  2195.  
  2196.             fseek(tablefd,fcClx,SEEK_SET);
  2197.             getc(tablefd);
  2198.             nopieces = get_piecetable(tablefd,&rgfc,&avalrgfc,&sprm,&clxcount);
  2199.  
  2200.             
  2201.             fcvalue = get_fc_from_cp(portions->ccpFtn+oldccpText+begin,rgfc,avalrgfc,nopieces);
  2202.  
  2203.             free(rgfc);
  2204.             free(avalrgfc);
  2205.             free(sprm);
  2206.             error(erroroutput,"standard footer, fcvalue is %x, old method %d\n",fcvalue,portions->fcMin+portions->ccpFtn+oldccpText+begin);
  2207.             
  2208.         /*    
  2209.             fseek(mainfd,portions->fcMin+portions->ccpFtn+oldccpText+begin,SEEK_SET);
  2210.         */
  2211.     
  2212.             fseek(mainfd,fcvalue,SEEK_SET);
  2213.     
  2214.             tempcp=cp;
  2215.             portions->ccpText = len;
  2216.             cp=begin;
  2217.             tempfields=all_fields[0];
  2218.             all_fields[0] = all_fields[1];
  2219.             realcp = oldccpText+portions->ccpFtn+begin;
  2220.             
  2221.             decode_simple(mainfd,tablefd,data,fcClx,fcvalue,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,1);
  2222.             
  2223.             all_fields[0] = tempfields;
  2224.             cp=tempcp;
  2225.             realcp = tempcp;
  2226.             fseek(mainfd,headerpos,SEEK_SET);
  2227.             portions->ccpText = oldccpText;
  2228.             header--;
  2229.             error(erroroutput,"ending footer\n");
  2230.             }
  2231.  
  2232.         ret = 1;
  2233.         pagenumber++;
  2234.         sectionpagenumber++;
  2235.         init_chp(&achp);
  2236.         decode_s_chp(&achp,fontnamelist);
  2237.         }
  2238.     return(ret);
  2239.     }
  2240.  
  2241. void decode_simple_header(FILE *mainfd,FILE *tablefd,FILE *data,sep *asep,U32 fcClx,U32 fcMin,U32 fcMac,U32 intervals,U32 chpintervals,U32 *plcfbtePapx,U32 *plcfbteChpx,field_info *all_fields[5],list_info *a_list_info,style *sheet,textportions *portions,ffn *fontnamelist,int flag)
  2242.     {
  2243.     U32 headerpos;
  2244.     U32 oldccpText;
  2245.     U32 begin=0;
  2246.     U32 len=0;
  2247.     int tempcp;
  2248.     int temprealcp;
  2249.     field_info *tempfields;
  2250.     int i;
  2251.     int nopieces;
  2252.     U32 *avalrgfc=NULL;
  2253.     U32 *rgfc=NULL;
  2254.     U16 *sprm=NULL;
  2255.     U32 fcvalue;
  2256.     U32 clxcount=0;
  2257.  
  2258.     if (noheaders)
  2259.         return;
  2260.     
  2261.  
  2262.     if (header == 0)
  2263.         {
  2264.         error(erroroutput,"doing header\n");
  2265.         for (i=0;i<1;i++)
  2266.             {
  2267.             if (i==0)
  2268.                 decode_header(&begin,&len,portions,asep);
  2269. #if 0
  2270.             /*
  2271.             im ignoring this for now, i think this is
  2272.             a header textbox, so ill hold off on this 
  2273.             until i get it right
  2274.             */
  2275.             else
  2276.                 decode_header2(&begin,&len,portions);
  2277. #endif
  2278.                 
  2279.             if ((begin != -1) && (len != -1))
  2280.                 {
  2281.                 
  2282.                 fseek(tablefd,fcClx,SEEK_SET);
  2283.                 getc(tablefd);
  2284.                 nopieces = get_piecetable(tablefd,&rgfc,&avalrgfc,&sprm,&clxcount);
  2285.                 
  2286.  
  2287.                 headerpos = ftell(mainfd);
  2288.                 oldccpText = portions->ccpText;
  2289.                 header++;
  2290.  
  2291.                 fcvalue = get_fc_from_cp(portions->ccpFtn+oldccpText+begin,rgfc,avalrgfc,nopieces);
  2292.                 
  2293.                 fseek(mainfd,fcvalue,SEEK_SET);
  2294.  
  2295.                 free(avalrgfc);
  2296.                 free(rgfc);
  2297.                 free(sprm);
  2298.  
  2299.                 tempcp=cp;
  2300.                 portions->ccpText = len;
  2301.                 cp=begin;
  2302.                 tempfields = all_fields[0];
  2303.                 all_fields[0] = all_fields[1];
  2304.                 error(erroroutput,"overall header begin is %x\n",portions->fcMin+oldccpText+portions->ccpFtn+begin);
  2305.                 error(erroroutput,"fcvalue is %x\n, ordinary seek is %x",fcvalue,portions->fcMin+portions->ccpFtn+oldccpText+begin);
  2306.                 temprealcp = realcp;
  2307.                 realcp = oldccpText+portions->ccpFtn+begin;
  2308.                 inaheaderfooter=1;
  2309.                 decode_simple(mainfd,tablefd,data,fcClx,fcvalue,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,1);
  2310.                 inaheaderfooter=0;
  2311.                 all_fields[0] = tempfields;
  2312.                 cp=tempcp;
  2313.                 realcp = temprealcp;
  2314.                 error(erroroutput,"after header realcp is %x\n",realcp);
  2315.                 fseek(mainfd,headerpos,SEEK_SET);
  2316.                 portions->ccpText = oldccpText;
  2317.                 header--;
  2318.                 error(erroroutput,"ending header\n");
  2319.                 }
  2320.             }
  2321.  
  2322.         }
  2323.     }
  2324.  
  2325. void get_next_f_ref(textportions *portions,signed long *nextfootnote)
  2326.     {
  2327.     int i;
  2328.     if (portions->fndref_no > 0)
  2329.         {
  2330.         /*then there might be footnotes to look out for*/
  2331.         for(i=0;i<portions->fndref_no;i++)
  2332.             {
  2333.             error(erroroutput,"footnote blah %d, %ld, %ld",portions->fndFRD[i],*nextfootnote,portions->fndRef[i]);
  2334.             if ( (portions->fndFRD[i] <= 0) && (*nextfootnote < portions->fndRef[i]) )
  2335.                 {
  2336.                 /*not automatically numbered, so we have to look out for it manually*/
  2337.                 *nextfootnote = portions->fndRef[i];
  2338.                 error(erroroutput,"the next footnote is at cp %x\n",*nextfootnote);
  2339.                 break;
  2340.                 }
  2341.             }
  2342.         
  2343.         }
  2344.     }
  2345.  
  2346. void get_next_e_ref(textportions *portions,signed long *nextendnote)
  2347.     {
  2348.     int i;
  2349.     if (portions->endref_no > 0)
  2350.         {
  2351.         /*then there might be endnotes to look out for*/
  2352.         for(i=0;i<portions->endref_no;i++)
  2353.             {
  2354.             error(erroroutput,"endnote blah %d, %ld, %ld",portions->endFRD[i],*nextendnote,portions->endRef[i]);
  2355.             if ( (*nextendnote) < portions->endRef[i] )
  2356.                 {
  2357.                 /*not automatically numbered, so we have to look out for it manually*/
  2358.                 *nextendnote = portions->endRef[i];
  2359.                 error(erroroutput,"the next endnote is at cp %x\n",*nextendnote);
  2360.                 break;
  2361.                 }
  2362.             }
  2363.         
  2364.         }
  2365.     }
  2366.  
  2367. void decode_simple(FILE *mainfd,FILE *tablefd,FILE *data,U32 fcClx,U32 fcMin,U32 fcMac,U32 intervals,U32 chpintervals,U32 *plcfbtePapx,U32 *plcfbteChpx,field_info *all_fields[5],list_info *a_list_info,style *sheet,textportions *portions,ffn *fontnamelist,int flag)
  2368.     {
  2369.     
  2370.     U32 nextfc=0;
  2371.     U32 tapfc1=0;
  2372.     
  2373.     U32 nextchpfc=0;
  2374.     U32 lastfc=0;
  2375.     U32 lastchpfc=0;
  2376.     U32 internalcp;
  2377.     U32 limitcp;
  2378.     pap *apap;
  2379.     chp *achp;
  2380.     sep *asep=NULL;
  2381.     sep *tempsep=NULL;
  2382.     pap *tappap= NULL;
  2383.     pap *temppap = NULL;
  2384.     chp *tempchp = NULL;
  2385.     int i,j;
  2386.     int letter;
  2387.     int tempfck;
  2388.     int newpage=1;
  2389.     U32 thisfc;
  2390.     U32 sepxfc;
  2391.     
  2392.  
  2393.     U32 *rgfc=NULL;
  2394.     U32 *avalrgfc=NULL;
  2395.     
  2396.     U16 *sprm=NULL;
  2397.     U32 clxcount=0;
  2398.     int nopieces;
  2399.     signed long nextfootnote=0;
  2400.     signed long nextendnote=0;
  2401.     U32 nextbookmark_b=realcp; /*was 0*/
  2402.     U32 nextbookmark_e=realcp; /*was 0*/
  2403.  
  2404.     U32 untilfc=0;
  2405.  
  2406.     int flag_8_16=0;
  2407.  
  2408.     int d_count=0;
  2409.  
  2410.     U32 nextpiece=0;
  2411.  
  2412.     int issection=1;
  2413.  
  2414.     U32 sepcp;
  2415.  
  2416.     
  2417.  
  2418.     int charsetflag=0;
  2419.  
  2420.  
  2421.     apap = NULL;
  2422.     achp = NULL;
  2423.     nextfc=fcMin;
  2424.     nextchpfc=fcMin;
  2425.  
  2426.  
  2427.     error(erroroutput,"all text begins %ld %x ends at %ld %x, main text ends at %ld %x\n",fcMin,fcMin,fcMac,fcMac,portions->ccpText+fcMin,portions->ccpText+fcMin);
  2428.  
  2429.  
  2430.     fseek(tablefd,fcClx,SEEK_SET);
  2431.     getc(tablefd);
  2432.         
  2433.     error(erroroutput,"begin simple fcClx is (%x)",fcClx);
  2434.     /*
  2435.     hmm, simple files can be start off in 8 bit and go to 16
  2436.     bit and vice versa, is so the piecetable can be used to determine these
  2437.     limits
  2438.     */
  2439.     nopieces = get_piecetable(tablefd,&rgfc,&avalrgfc,&sprm,&clxcount);
  2440.     if (nopieces > 1)
  2441.         error(erroroutput,"ah shit!, buggering microsoft over-complex toolkits!!!!, theres NO call for this dumb *piece* technology anyway\n");
  2442.  
  2443.     /*
  2444.     right so this is to guess (over safely) whether to go into unicode mode or not for
  2445.     the full html document, if i get it wrong then well ill get away with it wih utf-8 encoding
  2446.     coz i believe as ms only uses 8 bit for west european languages as far as i can tell
  2447.     */
  2448.     if (header==0)
  2449.         {
  2450.         i=0;
  2451.         while(i<nopieces)
  2452.             {
  2453.             if (avalrgfc[i] & 0x40000000UL)
  2454.                 {
  2455.                 /*
  2456.                 flag_8_16=0;
  2457.                 untilfc=fcMin+portions->ccpText;
  2458.                 */
  2459.                 error(erroroutput,"hokay, simple text is ascii 8 bit stuff\n");
  2460.                 }
  2461.             else
  2462.                 {
  2463.                 /*
  2464.                 flag_8_16=1;
  2465.                 untilfc=fcMin+portions->ccpText+portions->ccpText;
  2466.                 */
  2467.                 error(erroroutput,"hokay, simple text is unicode 16 bit stuff\n");
  2468.                 charsetflag=1;
  2469.                 /*
  2470.                 if (header == 0)
  2471.                     {
  2472.                     fprintf(outputfile,"\n<head>\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=utf-8\">\n</head>\n");
  2473.                     break;
  2474.                     }
  2475.                 */
  2476.                 }
  2477.             i++;
  2478.             }
  2479.     
  2480.         if (charsetflag == 0)
  2481.             fprintf(outputfile,"\n<head>\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">\n</head>\n");
  2482.         else
  2483.             fprintf(outputfile,"\n<head>\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=utf-8\">\n</head>\n");
  2484.  
  2485.         
  2486.         fprintf(outputfile,"<body>\n");
  2487.         }
  2488.  
  2489.     /*now we have a problem as some simple (hah!!!) docs can go from 16 bit text to 
  2490.     8 bit and vice versa depending on the piece table, so keep an eye on that
  2491.     so as to know how to twiddle the flags*/
  2492.     /*find the smallest piece greater than or equal to the realcp*/
  2493.     i=0;
  2494.  
  2495.     while(i<nopieces)
  2496.         {
  2497.         error(erroroutput,"realcp is %x, rgfc[i+1] is %x\n",realcp,rgfc[i+1]);
  2498.         if (rgfc[i+1] > realcp)
  2499.             {
  2500.             nextpiece = rgfc[i+1];
  2501.             if (avalrgfc[i] & 0x40000000UL)
  2502.                 {
  2503.                 flag_8_16=0;
  2504.                 untilfc=fcMin+portions->ccpText;
  2505.                 }
  2506.             else
  2507.                 {
  2508.                 flag_8_16=1;
  2509.                 untilfc=fcMin+portions->ccpText+portions->ccpText;
  2510.                 }
  2511.             break;
  2512.             }
  2513.         i++;
  2514.         }
  2515.  
  2516.  
  2517.     error(erroroutput,"end simple fcClx is (%x)",fcClx);
  2518.  
  2519.     error(erroroutput,"end fc is %x\n",fcMin+portions->ccpText);
  2520.  
  2521.     if  ( (flag < 2) && (flag >0) )
  2522.         {
  2523.         untilfc=-1;  /*max it out for header/footers and rely on doubled 0x0d's*/
  2524.         limitcp=-1;
  2525.         }
  2526.     else
  2527.         limitcp=portions->ccpText;
  2528.  
  2529.     /*portions->cppText gives the amount of chars to handle*/
  2530.     i=fcMin;
  2531.     internalcp=0;
  2532.  
  2533.  
  2534.     error(erroroutput,"fcMin is %x,untilfc is %x, it would be %x, limitcp is %x, nextpiece is %x\n",fcMin,untilfc,untilfc-fcMin,limitcp,nextpiece);
  2535.     while(internalcp < limitcp)
  2536.         {
  2537.         error(erroroutput,"real cp is %x nextpiece is %x\n",realcp,nextpiece);
  2538.         if (nextpiece == realcp)
  2539.             {
  2540.             error(erroroutput,"have to get next piece for simple text mode\n");
  2541.             /*
  2542.             here we should actually do a seek to the fc, and see if this
  2543.             nextpiece thing is ok
  2544.             */
  2545.             j=0;
  2546.  
  2547.             while(j<nopieces)
  2548.                 {
  2549.                 if (rgfc[j+1] > realcp)
  2550.                     {
  2551.                     nextpiece = rgfc[j+1];
  2552.                     if (avalrgfc[j] & 0x40000000UL)
  2553.                         flag_8_16=0;
  2554.                         
  2555.                     else
  2556.                         flag_8_16=1;
  2557.                         
  2558.                     if (avalrgfc[j] & 0x40000000UL)
  2559.                         {
  2560.                         error(erroroutput,"THUS this fc is %x\n",(avalrgfc[j]&0xbfffffffUL)/2);
  2561.                         thisfc = (avalrgfc[j]&0xbfffffffUL)/2;
  2562.                         }
  2563.                     else
  2564.                         {
  2565.                         error(erroroutput,"THUS fc is %x\n",avalrgfc[j]);
  2566.                         thisfc = avalrgfc[j];
  2567.                         }
  2568.                     fseek(mainfd,thisfc,SEEK_SET);
  2569.                     i = thisfc;
  2570.                     /*force new paragraph and chp check*/
  2571.                     nextfc=i;
  2572.                     error(erroroutput,"SEEK: we're at %x, flag is %d\n",ftell(mainfd),flag_8_16);
  2573.                     break;
  2574.                     }
  2575.                 j++;
  2576.                 }
  2577.             }
  2578.  
  2579.         /*get the sep*/
  2580.         if (flag == 0)
  2581.             if (issection)
  2582.                 {
  2583.                 error(erroroutput,"getting sep, %x, piece is %d\n",realcp,i);
  2584.                 sepxfc = find_FC_sepx(realcp,&sepcp,portions);
  2585.                 tempsep = asep;
  2586.                 asep = get_sep(sepxfc,mainfd);
  2587.                 if (decode_simple_endnote(mainfd,tablefd,data,asep,fcClx,fcMin,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,flag))
  2588.                     fprintf(outputfile,"\n<br><img src=\"%s/endnoteend.gif\"><br>\n",patterndir());
  2589.                     
  2590.                 if (pagenumber!=1)
  2591.                     sectionbreak(asep);
  2592.  
  2593.                 if (asep != NULL)
  2594.                     {
  2595.                     if (tempsep != NULL)
  2596.                         free(tempsep);
  2597.                     tempsep=NULL;
  2598.                     }
  2599.                 else
  2600.                     {
  2601.                     asep = tempsep;
  2602.                     tempsep=NULL;
  2603.                     }
  2604.                     
  2605.                 issection=0;
  2606.                 }
  2607.         
  2608.         /*
  2609.         go down through all the text, when we hit a new page spit out the 
  2610.         header
  2611.         */
  2612.         error(erroroutput,"fc is %ld (%X)\n",i,i);
  2613.         if (newpage)
  2614.             {
  2615.             if (!inatable)
  2616.                 {
  2617.                 newpage=0;
  2618.                 decode_simple_header(mainfd,tablefd,data,asep,fcClx,fcMin,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,flag);
  2619.                 error(erroroutput,"end: flag is %d\n",flag);
  2620.                 /*force new paragraph and chp check*/
  2621.                 nextfc=i;
  2622.                 }
  2623.             else
  2624.                 deferrednewpage=1;
  2625.             }
  2626.  
  2627.  
  2628.         /*get the pap*/
  2629.         if (i == nextfc) 
  2630.             {
  2631.             lastfc = i;
  2632.             temppap = apap;
  2633.             tempfck = find_FKPno_papx(i,plcfbtePapx,intervals);
  2634.             if (tempfck != -1)
  2635.                 {
  2636.                 apap = get_pap(tempfck,mainfd,i,&nextfc,sheet,a_list_info);
  2637.                 error(erroroutput,"next para is at %x\n",nextfc);
  2638.                 }
  2639.             
  2640.             if (apap == NULL)
  2641.                 {
  2642.                 error(erroroutput,"found no pap, reverting to previous\n");
  2643.                 apap = temppap;
  2644.                 temppap=NULL;
  2645.                 }
  2646.             else if (temppap != NULL)
  2647.                 {
  2648.                 /*last gasp of the pap*/
  2649.                 end_para(temppap,apap);
  2650.                 free(temppap);
  2651.                 temppap=NULL;
  2652.                 }
  2653.             else
  2654.                 end_para(NULL,apap);
  2655.  
  2656.             /*if table set search for tap*/
  2657.             if (apap->fInTable)
  2658.                 {
  2659.                 tapfc1 = i;
  2660.                 error(erroroutput,"we search for the tap here\n");
  2661.                 error(erroroutput,"tappap nexts are %x, i is %x\n",tapfc1,i);
  2662.                 do
  2663.                     {
  2664.                     if (tappap != NULL)
  2665.                         {
  2666.                         free(tappap);
  2667.                         tappap=NULL;
  2668.                         }
  2669.                         
  2670.                     error(erroroutput,"tappap nexts are %x\n",tapfc1);
  2671.                     tempfck = find_FKPno_papx(tapfc1,plcfbtePapx,intervals);
  2672.                     if (tempfck != -1)
  2673.                         tappap = get_pap(tempfck,mainfd,tapfc1,&tapfc1,sheet,a_list_info);
  2674.                     else
  2675.                         break;
  2676.                     }
  2677.                 while( (tappap != NULL) && (!tappap->fTtp) );
  2678.                 error(erroroutput,"finished search for the tap here\n");
  2679.                 /*
  2680.                 at this stage tappap has the correct row structure stored in it
  2681.                 that we want apap to have
  2682.                 */
  2683.                 if (tappap != NULL)
  2684.                     {
  2685.                     copy_tap(&(apap->ourtap),&(tappap->ourtap));
  2686.                     error(erroroutput,"no of cells is %d, %d\n",apap->ourtap.cell_no,tappap->ourtap.cell_no);
  2687.                     free(tappap);
  2688.                     tappap=NULL;
  2689.                     }
  2690.                 }
  2691.             }
  2692.  
  2693.         /* get the chp, using the paps istd for a basis*/
  2694.         if ((i == nextchpfc) || (lastfc == i)) 
  2695.             {
  2696.             lastchpfc=i;
  2697.             error(erroroutput,"looking for chp\n");
  2698.             tempchp = achp;
  2699.             tempfck = find_FKPno_chpx(i,plcfbteChpx,chpintervals);
  2700.             if (tempfck != -1)
  2701.                 achp = get_chp(tempfck,mainfd,data,i,&nextchpfc,sheet,apap->istd);
  2702.  
  2703.             if (achp == NULL)
  2704.                 {
  2705.                 error(erroroutput,"found no chp, reverting to previous\n");
  2706.                 achp = tempchp;
  2707.                 }
  2708.             else if (tempchp != NULL)
  2709.                 {
  2710.                 free(tempchp);
  2711.                 tempchp=NULL;
  2712.                 }
  2713.  
  2714.             if (achp->color[0] == '\0')
  2715.                 {
  2716.                 if (flag == 1)
  2717.                     {
  2718.                     strcpy(achp->color,"#7f5555");
  2719.                     error(erroroutput,"color set\n");
  2720.                     }
  2721.                 else if (flag == 2)
  2722.                     {
  2723.                     strcpy(achp->color,"#330099");
  2724.                     error(erroroutput,"color set\n");
  2725.                     }
  2726.                 else if (flag == 3)
  2727.                     {
  2728.                     strcpy(achp->color,"#ff7777");
  2729.                     error(erroroutput,"color set\n");
  2730.                     }
  2731.                 else 
  2732.                     {
  2733.                     error(erroroutput,"color not set\n");
  2734.                     }
  2735.                 }
  2736.  
  2737.             error(erroroutput,"the next char lim is %d (%x)\n",nextchpfc,nextchpfc);
  2738.             
  2739.             decode_e_list(apap,achp,a_list_info);
  2740.             decode_e_chp(achp);
  2741.             }
  2742.             
  2743.         /*after we have a new pap, do the special codes*/
  2744.         if (lastfc == i)
  2745.             {
  2746.             decode_e_specials(apap,achp,a_list_info);
  2747.             decode_e_table(apap,achp,a_list_info);
  2748.             decode_s_table(apap,achp,a_list_info);
  2749.             decode_s_specials(apap,achp,a_list_info);
  2750.             decode_s_chp(achp,fontnamelist);
  2751.             }
  2752.  
  2753.         if (lastchpfc == i) 
  2754.             {
  2755.             decode_s_chp(achp,fontnamelist);
  2756.             lastchpfc = 0;
  2757.             }
  2758.  
  2759.  
  2760.         if (flag_8_16)
  2761.             letter = read_16ubit(mainfd);
  2762.         else
  2763.             letter = getc(mainfd);
  2764.  
  2765.  
  2766.         if (lastfc == i)
  2767.             {
  2768.             if ( ((letter != 12) && (letter != 13))  )
  2769.                 {
  2770.                 error(erroroutput,"doing list and next letter is %c %x\n",letter,letter);
  2771.                 decode_s_list(apap,achp,a_list_info,fontnamelist,DONTIGNORENUM);
  2772.                 }
  2773.             else
  2774.                 error(erroroutput,"a special list\n");
  2775.                 
  2776.                 
  2777.             lastfc = 0;
  2778.             }
  2779.  
  2780.         if (flag)
  2781.             {
  2782.             if (letter == 13)
  2783.                 {
  2784.                 /*
  2785.                 headers and footers seem to continue until 2 0x0d are reached, they dont
  2786.                 appear after all to go until the len derived from the header table
  2787.                 like i thought originally.
  2788.                 */
  2789.                 d_count++;
  2790.                 if (d_count == 2)
  2791.                     break;
  2792.                 }
  2793.             else
  2794.                 d_count=0;
  2795.             }
  2796.  
  2797.  
  2798.         if ( (cp == nextfootnote) && (flag == 0) ) 
  2799.             {
  2800.             decode_f_reference(portions);
  2801.             get_next_f_ref(portions,&nextfootnote);
  2802.             }
  2803.  
  2804.         if ( (cp == nextendnote) && (flag == 0) ) 
  2805.             {
  2806.             decode_e_reference(portions);
  2807.             get_next_e_ref(portions,&nextendnote);
  2808.             }
  2809.  
  2810.         
  2811.             
  2812.  
  2813.         while (realcp == nextbookmark_b)
  2814.             nextbookmark_b = decode_b_bookmark(&(portions->l_bookmarks),&(portions->bookmarks));
  2815.  
  2816.         while (realcp == nextbookmark_e)
  2817.             nextbookmark_e = decode_e_bookmark(&(portions->l_bookmarks));
  2818.  
  2819.         newpage = decode_letter(letter,flag_8_16,apap,achp,all_fields[0],mainfd,data,fontnamelist,a_list_info,portions,&issection);
  2820.  
  2821.         if (newpage)
  2822.             {
  2823.             error(erroroutput,"this one\n");
  2824.             /*if we are in a table defer the pagebreaking until after the end of the row, and then pagebreak*/
  2825.  
  2826.             if ((inatable)  && newpage == 2)
  2827.                 {
  2828.                 /*in this case we have ended a row, so we should take the opportunity to halt the table*/
  2829.                 fprintf(outputfile,"\n</table>\n");
  2830.                 inatable=0;
  2831.                 newpage=1;
  2832.                 }
  2833.             
  2834.             if ((!inatable) && (newpage == 1))
  2835.                 {
  2836.                 decode_simple_footer(mainfd,tablefd,data,asep,fcClx,fcMin,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,flag);
  2837.                 if (!issection)
  2838.                     pagebreak();
  2839.                     
  2840.                 }
  2841.             else if (newpage == 1)
  2842.                 deferrednewpage=1;
  2843.                 
  2844.             }
  2845.  
  2846.  
  2847.             
  2848.         if (flag_8_16)
  2849.             i+=2;
  2850.         else
  2851.             i++;
  2852.         internalcp++;
  2853.         }
  2854.  
  2855.     if (apap == NULL)
  2856.         {
  2857.         apap = (pap *)malloc(sizeof(pap));
  2858.         if (apap == NULL)
  2859.             {
  2860.             fprintf(erroroutput,"no mem available!\n");
  2861.             return;
  2862.             }
  2863.         }
  2864.     init_pap(apap);
  2865.     decode_e_list(apap,achp,a_list_info);
  2866.     decode_e_specials(apap,achp,a_list_info);
  2867.     decode_e_table(apap,achp,a_list_info);
  2868.  
  2869.     if (!newpage)
  2870.         {
  2871.         error(erroroutput,"the other one\n");
  2872.         decode_simple_footer(mainfd,tablefd,data,asep,fcClx,fcMin,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,flag);
  2873.         if (decode_simple_endnote(mainfd,tablefd,data,asep,fcClx,fcMin,fcMac,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,flag))
  2874.             fprintf(outputfile,"\n<br><img src=\"%s/endnoteend.gif\"><br>\n",patterndir());
  2875.         }
  2876.  
  2877.     if (rgfc != NULL)
  2878.         free(rgfc);    
  2879.     if (avalrgfc != NULL)
  2880.         free(avalrgfc);
  2881.     if (sprm != NULL)
  2882.         free(sprm);
  2883.  
  2884.     if (achp != NULL)
  2885.         free(achp);
  2886.     if (apap != NULL)
  2887.         free(apap);
  2888.     if (asep != NULL)
  2889.         free(asep);
  2890.     }
  2891.  
  2892.  
  2893. void decode_header(U32 *begin,U32 *len,textportions *portions,sep *asep)
  2894.     {
  2895.     /*i dont know how these fields are working as of yet, the
  2896.     docs seem to be a bit dodgy*/
  2897.     int odd;
  2898.     int val,tval;
  2899.     *begin = -1;
  2900.     *len= -1;
  2901.  
  2902.  
  2903.     /*is this the first page of a section*/
  2904.     if ((sectionpagenumber==asep->pgnStart) && (asep->fTitlePage))
  2905.         {
  2906.         error(erroroutput,"checking for page 1 special header\n");
  2907.         if (portions->headercpno > 10)
  2908.             if (portions->headercplist[11] > portions->headercplist[10])
  2909.                 {
  2910.                 *begin = portions->headercplist[10];
  2911.                 *len = portions->headercplist[11]-portions->headercplist[10];
  2912.                 error(erroroutput,"header begin is %x end is %x\n",portions->headercplist[11],portions->headercplist[10]);
  2913.                 return;
  2914.                 }
  2915.         if (asep->fTitlePage)
  2916.             return;
  2917.                 
  2918.         /*crazed bit of logic here :-)*/
  2919.         if (portions->headercpno > 13)
  2920.             if (portions->headercplist[portions->headercpno-1] > (portions->headercplist[10]+3))
  2921.                 return;
  2922.         }
  2923.     
  2924.     /*if nothing was found continue, and pull out ordinary header*/
  2925.  
  2926.     if ((sectionpagenumber/2)*2 == sectionpagenumber)
  2927.         odd=0;
  2928.     else 
  2929.         odd=1;
  2930.  
  2931.     *len=0;
  2932.  
  2933.  
  2934.     /*if index 8 is larger than index 7 i think thats the boundaries
  2935.     of header for all pages*/
  2936.  
  2937.     tval = 6+(6*(sectionno-1)); /*hairy test*/
  2938.  
  2939.     val = tval;
  2940.     error(erroroutput,"header val is %d, odd is %d, pagenumber is %d\n",val,odd,pagenumber);
  2941.  
  2942.     if (!odd)
  2943.         {
  2944.         while ((*len==0) && (val>0))
  2945.             {
  2946.             if (portions->headercpno > val)
  2947.                 {
  2948.                 if (portions->headercplist[val+1] > portions->headercplist[val])
  2949.                     {
  2950.                     *begin = portions->headercplist[val];
  2951.                     *len = portions->headercplist[val+1]-portions->headercplist[val];
  2952.                     error(erroroutput,"header begin is %x end is %x\n",portions->headercplist[val],portions->headercplist[val+1]);
  2953.                     }
  2954.                 }
  2955.             else
  2956.                 error(erroroutput,"well arse!!!, ive got the wrong idea about headers\n");
  2957.             val-=6;
  2958.             }
  2959.         }
  2960.  
  2961.     val=tval;
  2962.     
  2963.     if ((odd) || (*len == 0))
  2964.         {
  2965.         while ((*len==0) && (val>0))
  2966.             {
  2967.             if (portions->headercpno > val+1)
  2968.                 {
  2969.                 error(erroroutput,"val is %d headercplist[val+2] %x headercplist[val+1] %x\n",val,portions->headercplist[val+2],portions->headercplist[val+1]);
  2970.                 if (portions->headercplist[val+2] > portions->headercplist[val+1])
  2971.                     {
  2972.                     *begin = portions->headercplist[val+1];
  2973.                     *len = portions->headercplist[val+2]-portions->headercplist[val+1];
  2974.                     error(erroroutput,"this header begin is %x end is %x\n",portions->headercplist[val+1],portions->headercplist[val+2]);
  2975.                     }
  2976.                 }
  2977.             else
  2978.                 error(erroroutput,"well arse!!!, ive got the wrong idea about headers\n");
  2979.             val-=6;
  2980.             }
  2981.         }
  2982.  
  2983.     }
  2984.  
  2985. void decode_header2(U32 *begin,U32 *len,textportions *portions)
  2986.     {
  2987.  
  2988.     /*
  2989.     this is just a hacked together function, i have no basis for
  2990.     this at all except thats the output that word gets, dunno at all
  2991.     about this, im not seeing something obvious somewhere, hmm
  2992.     */
  2993.  
  2994.     /*i dont know how these fields are working as of yet, the
  2995.     docs seem to be a bit dodgy*/
  2996.     *begin = -1;
  2997.     *len= -1;
  2998.  
  2999.     /*is this the first page of a section*/
  3000.     if (sectionpagenumber==1)
  3001.         return;
  3002.     
  3003.     /*if index 8 is larger than index 7 i think thats the boundaries
  3004.     of header for all pages*/
  3005.     if (portions->headercpno > 12)
  3006.         if (portions->headercplist[13] > portions->headercplist[12])
  3007.             {
  3008.             *begin = portions->headercplist[12];
  3009.             *len = portions->headercplist[13]-portions->headercplist[12];
  3010.             error(erroroutput,"header begin is %x end is %x\n",portions->headercplist[12],portions->headercplist[13]);
  3011.             }
  3012.     else
  3013.         error(erroroutput,"well arse!!!, ive got the wrong idea about headers\n");
  3014.  
  3015.     }
  3016.  
  3017.  
  3018. void decode_endnote(U32 *begin,U32 *len,textportions *portions,int i)
  3019.     {
  3020.     error(erroroutput,"endnote cp begin is %x end is %x\n",portions->endTxt[i],portions->endTxt[i+1]);
  3021.     *begin = portions->endTxt[i];
  3022.     *len = portions->endTxt[i+1]-*begin;
  3023.     }
  3024.  
  3025. void decode_footnote(U32 *begin,U32 *len,textportions *portions,int i)
  3026.     {
  3027.     error(erroroutput,"footnote cp begin is %x end is %x\n",portions->fndTxt[i],portions->fndTxt[i+1]);
  3028.     *begin = portions->fndTxt[i];
  3029.     *len = portions->fndTxt[i+1]-*begin;
  3030.     }
  3031.  
  3032. void decode_footanno(U32 *begin,U32 *len,textportions *portions,int i)
  3033.     {
  3034.     error(erroroutput,"annotation cp begin is %x end is %x\n",portions->andTxt[i],portions->andTxt[i+1]);
  3035.     *begin = portions->andTxt[i];
  3036.     *len = portions->andTxt[i+1]-*begin;
  3037.     }
  3038.  
  3039. void decode_footer(U32 *begin,U32 *len,textportions *portions,sep *asep)
  3040.     {
  3041.     /*i dont know how these fields are working as of yet, the
  3042.     docs seem to be a bit dodgy*/
  3043.     int odd;
  3044.     int val,tval;
  3045.     *begin = -1;
  3046.     *len= -1;
  3047.     
  3048.     error(erroroutput,"pagenumber is %d,sectionpagenumber is %d, pgnStart is %d, title is %d\n",pagenumber, sectionpagenumber,asep->pgnStart,asep->fTitlePage);
  3049.  
  3050.     if ((sectionpagenumber==asep->pgnStart) && (asep->fTitlePage))
  3051.         {
  3052.         error(erroroutput,"checking for page 1 special footer\n");
  3053.         if (portions->headercpno > 12)
  3054.             {
  3055.             if (portions->headercplist[12] > portions->headercplist[11])
  3056.                 {
  3057.                 *begin = portions->headercplist[11];
  3058.                 *len = portions->headercplist[12]-portions->headercplist[11];
  3059.                 fprintf(outputfile,"\n<hr width=\"50%%\">\n");
  3060.                 error(erroroutput,"header begin is %x end is %x\n",portions->headercplist[12],portions->headercplist[11]);
  3061.                 return;
  3062.                 }
  3063.             }
  3064.         if (asep->fTitlePage)
  3065.             return;
  3066.  
  3067.         /*crazed bit of logic here :-)*/
  3068.         if (portions->headercpno > 14)
  3069.             if (portions->headercplist[portions->headercpno-1] > (portions->headercplist[11]+3))
  3070.                 return;
  3071.         }
  3072.  
  3073.     /*else contunue down the wire*/
  3074.     /*
  3075.     if its an odd page look at that, return the appropiate portion,
  3076.     if that is 0 len then return the even*/
  3077.     /*if index 10 is larger than index 9 i think thats the boundaries
  3078.     of header for odd(or all) pages*/
  3079.  
  3080.  
  3081.     if ((sectionpagenumber/2)*2 == sectionpagenumber)
  3082.         odd=0;
  3083.     else 
  3084.         odd=1;
  3085.  
  3086. /*
  3087.     fprintf(outputfile,"\n<hr width=\"50%%\">\n");
  3088. */
  3089.  
  3090.     *len=0;
  3091.  
  3092.     tval = 8+ ((sectionno-1)*6);
  3093.  
  3094.     error(erroroutput,"odd is %d, section no is %d, tval is %d, *len is %d\n",odd,sectionno,tval,*len);
  3095.  
  3096.     val=tval;
  3097.     if (!odd)
  3098.         {
  3099.         while ((*len == 0) && (val > 0))
  3100.             {
  3101.             if (portions->headercpno > val)
  3102.                 {
  3103.                 if (portions->headercplist[val+1] > portions->headercplist[val])
  3104.                     {
  3105.                     *begin = portions->headercplist[val];
  3106.                     *len = portions->headercplist[val+1]-portions->headercplist[val];
  3107.                     fprintf(outputfile,"\n<hr width=\"50%%\">\n");
  3108.                     error(erroroutput,"even begin is %x end is %x\n",portions->headercplist[val],portions->headercplist[val+1]);
  3109.                     }
  3110.                 }
  3111.             else
  3112.                 error(erroroutput,"well arse!!!, ive got the wrong idea about footers val %d\n",portions->headercpno);
  3113.             val-=6;
  3114.             }
  3115.         }
  3116.  
  3117.     val = tval;
  3118.  
  3119.     if ( (odd) || (*len == 0))
  3120.         {
  3121.         while ((*len == 0) && (val > 0))
  3122.             {
  3123.             if (portions->headercpno > val+1)
  3124.                 {
  3125.                 if (portions->headercplist[val+2] > portions->headercplist[val+1])
  3126.                     {
  3127.                     *begin = portions->headercplist[val+1];
  3128.                     *len = portions->headercplist[val+2]-portions->headercplist[val+1];
  3129.                     fprintf(outputfile,"\n<hr width=\"50%%\">\n");
  3130.                     error(erroroutput,"odd begin is %x end is %x\n",portions->headercplist[val+1],portions->headercplist[val+2]);
  3131.                     }
  3132.                 }
  3133.             else
  3134.                 error(erroroutput,"well arse!!!, ive got the wrong idea about footers val %d\n",portions->headercpno);
  3135.             val-=6;
  3136.             }
  3137.         }
  3138.         
  3139.     }
  3140.  
  3141.  
  3142. void decode_s_chp(chp *achp, ffn *fontnamelist)
  3143.     {
  3144.     ffn *tempfont;
  3145.     int i;
  3146.     error(erroroutput,"in start chp\n");
  3147.     if (chps)
  3148.         return;
  3149.     error(erroroutput,"still in start chp\n");
  3150.     error(erroroutput,"incolor is %s,font =%d, current font is %d, currentfont is %d, achpfont is %d\n", incolor,achp->fontsize,currentfontsize,currentfontcode,achp->ascii_font);
  3151.  
  3152.     if (achp->fStrike)
  3153.         strcpy(achp->color,"#ed32ff");        /*i just ensure that strike through text becomes this horrible shade of pink*/
  3154.     if (achp->fDStrike)
  3155.         strcpy(achp->color,"#ff7332");        
  3156.  
  3157.     if ((use_fontfacequery(achp) && (achp->ascii_font != currentfontcode)) || (achp->fontsize!=currentfontsize) || (strcmp(achp->color,incolor)) /* ( (achp->color[0] != '\0') && (!inacolor))  || ( (achp->color[0] == '\0' ) && (inacolor))*/   )
  3158.         {
  3159.         error(erroroutput,"b: font =%d %s\n", achp->fontsize,achp->color);
  3160.         if (inunderline)
  3161.             {
  3162.             fprintf(outputfile,"</U>");
  3163.             inunderline=0;
  3164.             }
  3165.         if (initalic)
  3166.             {
  3167.             fprintf(outputfile,"</I>");
  3168.             initalic=0;
  3169.             }
  3170.         if (inbold)
  3171.             {
  3172.             fprintf(outputfile,"</B>");
  3173.             inbold=0;
  3174.             }
  3175.         if (inblink)
  3176.             {
  3177.             fprintf(outputfile,"</BLINK>");
  3178.             inblink=0;
  3179.             }
  3180.         if (inafont)
  3181.             {
  3182.             inacolor=0;
  3183.             incolor[0] = '\0';
  3184.             fprintf(outputfile,"</font>");
  3185.             currentfontsize=NORMAL;
  3186.             inafont=0;
  3187.             }
  3188.  
  3189.         if ( (achp->color[0] != '\0') || (achp->fontsize!=currentfontsize) || ((use_fontfacequery(achp) && (achp->ascii_font != currentfontcode))))
  3190.             {
  3191.             fprintf(outputfile,"<font ");
  3192.             if ( (((achp->fontsize/2)-NORMAL/2) != 0) && (achp->fontsize!=NORMAL))
  3193.                 {
  3194.                 fprintf(outputfile,"size = \"%+d\" ", (achp->fontsize/2)-NORMAL/2);
  3195.                 inafont=1;
  3196.                 }
  3197.  
  3198.             if (achp->color[0] != '\0')
  3199.                 {
  3200.                 fprintf(outputfile,"color=\"%s\"", achp->color);
  3201.                 inafont=1;
  3202.                 inacolor=1;
  3203.                 }
  3204.  
  3205.             strcpy(incolor,achp->color);
  3206.  
  3207.             if (use_fontfacequery(achp))
  3208.                 {
  3209.                 /*do diggery pokery to get fontface*/
  3210.                 tempfont = get_fontnamefromcode(fontnamelist,achp->ascii_font, &i);
  3211.                 if (tempfont != NULL)
  3212.                     {
  3213.                     if (!strcmp(tempfont->name,"Times New Roman"))
  3214.                         fprintf(outputfile," face=\"%s,%s\"",tempfont->name,"Times");
  3215.                     else if (!strcmp(tempfont->name,"Courier New"))
  3216.                         fprintf(outputfile," face=\"%s,%s\"",tempfont->name,"Courier");
  3217.                     else 
  3218.                         fprintf(outputfile," face=\"%s,%s\"",tempfont->name,"Helvetica");
  3219.                     }
  3220.                 inafont=1;
  3221.                 }
  3222.  
  3223.             /*set currentfontface to this chps*/
  3224.             currentfontcode = achp->ascii_font;
  3225.  
  3226.             fprintf(outputfile,">");
  3227.             currentfontsize=achp->fontsize;
  3228.             }
  3229.         }
  3230.  
  3231.  
  3232.     if ((achp->supersubscript == 1) && (!insuper))
  3233.         {
  3234.         error(erroroutput,"superscript begins\n");
  3235.         fprintf(outputfile,"<SUP>");
  3236.         insuper=1;
  3237.         }
  3238.  
  3239.     if ((achp->supersubscript == 2) && (!insub))
  3240.         {
  3241.         error(erroroutput,"subscript begins\n");
  3242.         fprintf(outputfile,"<SUB>");
  3243.         insub=1;
  3244.         }
  3245.  
  3246.     error(erroroutput,"bold is %d\n",achp->fBold);
  3247.  
  3248.     if ((achp->animation) && (inblink == 0))
  3249.         {
  3250.         fprintf(outputfile,"<BLINK>");
  3251.         inblink=1;
  3252.         }
  3253.  
  3254.     if ((achp->fBold) && (inbold == 0))
  3255.         {
  3256.         fprintf(outputfile,"<B>");
  3257.         inbold=1;
  3258.         }
  3259.     
  3260.     if ((achp->fItalic) && (initalic==0))
  3261.         {
  3262.         fprintf(outputfile,"<I>");
  3263.         initalic=1;
  3264.         }
  3265.  
  3266.  
  3267.     if ((achp->underline) && (inunderline == 0))
  3268.         {
  3269.         fprintf(outputfile,"<U>");
  3270.         inunderline=1;
  3271.         }
  3272.  
  3273.     if ((achp->fStrike) && (instrike==0))
  3274.         {
  3275.         error(erroroutput,"STRIKETHROUGH");
  3276.         instrike=1;
  3277.         }
  3278.     }
  3279.  
  3280. void end_para(pap *apap,pap *newpap)
  3281.     {
  3282.     int height = 0;
  3283.     error(erroroutput,"THISend of para\n");
  3284.         
  3285.     if (apap != NULL)
  3286.         if (apap->fInTable == 1) 
  3287.             return;
  3288.  
  3289.     if (apap != NULL)
  3290.         {
  3291.         height = (apap->brcBottom>>24)&0x1f;
  3292.         error(erroroutput,"-->border depth is %d\n",height);
  3293.         
  3294.         if (newpap != NULL)
  3295.             {
  3296.             if (apap->brcLeft == newpap->brcLeft)
  3297.                 if (apap->brcRight == newpap->brcRight)
  3298.                     if (apap->fInTable == newpap->fInTable)
  3299.                         if (apap->dxaWidth == newpap->dxaWidth)
  3300.                             height = (apap->brcBetween>>24)&0x1f;    
  3301.             }
  3302.         }
  3303.     
  3304.     if (height > 1)
  3305.         {
  3306.         if (flushbreaks(0))
  3307.             {
  3308.             error(erroroutput,"<!--new paragraph-->");
  3309.             do_indent(apap);
  3310.             }
  3311.         error(erroroutput,"apap height\n");
  3312.         fprintf(outputfile,"\n<img width=1 height=%d src=\"%s/clear.gif\"><br>\n",height*2,patterndir());
  3313.         }
  3314.  
  3315.     if (apap != NULL)
  3316.         {
  3317.         if (apap->dyaAfter > 0)
  3318.             {
  3319.             if (flushbreaks(0))
  3320.                 {
  3321.                 error(erroroutput,"<!--new paragraph-->");
  3322.                 do_indent(apap);
  3323.                 }
  3324.             if (apap->dyaAfter/TWIRPS_PER_V_PIXEL > 1)
  3325.                 {
  3326.                 error(erroroutput,"apap height\n");
  3327.                 fprintf(outputfile,"\n<img width=1 height=%d src=\"%s/clear.gif\"><br>\n",apap->dyaAfter/TWIRPS_PER_V_PIXEL,patterndir());
  3328.                 }
  3329.             }
  3330.         }
  3331.  
  3332.  
  3333.  
  3334.     if (newpap != NULL)
  3335.         {
  3336.         if (newpap->fInTable == 1)  
  3337.             return;
  3338.  
  3339.         if (newpap->dyaBefore > 0)
  3340.             {
  3341.             if (flushbreaks(0))
  3342.                 {
  3343.                 error(erroroutput,"<!--new paragraph-->");
  3344.                 do_indent(newpap);
  3345.                 }
  3346.             if (newpap->dyaAfter/TWIRPS_PER_V_PIXEL >1)
  3347.                 {
  3348.                 error(erroroutput,"newpap height\n");
  3349.                 fprintf(outputfile,"\n<img width=1 height=%d src=\"%s/clear.gif\"><br>\n",newpap->dyaAfter/TWIRPS_PER_V_PIXEL,patterndir());
  3350.                 }
  3351.             }
  3352.         }
  3353.     }
  3354.  
  3355. void decode_e_chp(chp *achp)
  3356.     {
  3357.     int colorflag=0;
  3358.     error(erroroutput,"in end chp\n");
  3359.     if (chps)
  3360.         return;
  3361.  
  3362.     if (achp->fStrike)
  3363.         strcpy(achp->color,"#ed32ff");        /*i just ensure that strike through text becomes this horrible shade of pink*/
  3364.     if (achp->fDStrike)
  3365.         strcpy(achp->color,"#ff7332");        
  3366.  
  3367.     if ((achp->fStrike==0) && (instrike==1))
  3368.         {
  3369.         error(erroroutput,"END OF STRIKETHROUGH");
  3370.         instrike=0;
  3371.         }
  3372.  
  3373.     if ((inunderline== 1) && (achp->underline == 0))
  3374.         {
  3375.         inunderline=0;
  3376.         fprintf(outputfile,"</U>");
  3377.         }
  3378.  
  3379.     if ((initalic == 1) && (achp->fItalic == 0))
  3380.         {
  3381.         if (inunderline== 1)
  3382.             {
  3383.             inunderline=0;
  3384.             fprintf(outputfile,"</U>");
  3385.             }
  3386.         initalic=0;
  3387.         fprintf(outputfile,"</I>");
  3388.         }
  3389.  
  3390.     if ((inbold==1) && (!achp->fBold))
  3391.         {
  3392.         if (inunderline== 1)
  3393.             {
  3394.             inunderline=0;
  3395.             fprintf(outputfile,"</U>");
  3396.             }
  3397.         if (initalic == 1)
  3398.             {
  3399.             initalic=0;
  3400.             fprintf(outputfile,"</I>");
  3401.             }
  3402.         inbold=0;
  3403.         fprintf(outputfile,"</B>");
  3404.         }
  3405.  
  3406.     if ((inblink ==1) && (!achp->animation))
  3407.         {
  3408.         if (inunderline== 1)
  3409.             {
  3410.             inunderline=0;
  3411.             fprintf(outputfile,"</U>");
  3412.             }
  3413.         if (initalic == 1)
  3414.             {
  3415.             initalic=0;
  3416.             fprintf(outputfile,"</I>");
  3417.             }
  3418.         if (inbold== 1)
  3419.             {
  3420.             inbold=0;
  3421.             fprintf(outputfile,"</B>");
  3422.             }
  3423.         fprintf(outputfile,"</BLINK>");
  3424.         }
  3425.  
  3426.     if ((insuper==1) && (achp->supersubscript != 1))
  3427.         {
  3428.         insuper=0;
  3429.         if (footnotehack==1)
  3430.             {
  3431.             fprintf(outputfile,"</a>");
  3432.             footnotehack=0;
  3433.             }
  3434.         fprintf(outputfile,"</SUP>");
  3435.         }
  3436.  
  3437.     if ((insub) && (achp->supersubscript != 2))
  3438.         {
  3439.         insub=0;
  3440.         fprintf(outputfile,"</SUB>");
  3441.         }
  3442.  
  3443.  
  3444.     error(erroroutput,"the color is %s, %s\n",achp->color,incolor);
  3445. /*
  3446.     if ((inacolor) && (achp->color[0] == '\0'))
  3447.         colorflag=1;
  3448.     else*/
  3449.     if (strcmp(achp->color,incolor)) 
  3450.         colorflag=1;
  3451.         /*
  3452.     else if (achp->color[0] != '\0')
  3453.         if (incolor && (0 != strcmp(achp->color,incolor)) ) 
  3454.             colorflag=1;
  3455.         */
  3456.  
  3457.     error(erroroutput,"inafont is %d\n,currentfontcode is %d\n,achpfntcode is %d, color flag iss %d\n",inafont,currentfontcode,achp->ascii_font,colorflag);
  3458.  
  3459.     if ( ((inafont) && (achp->fontsize!=currentfontsize)) || colorflag || (currentfontcode != achp->ascii_font))
  3460.         {
  3461.         error(erroroutput,"font ended\n");
  3462.         if (inunderline== 1)
  3463.             {
  3464.             inunderline=0;
  3465.             fprintf(outputfile,"</U>");
  3466.             }
  3467.         if (initalic == 1)
  3468.             {
  3469.             initalic=0;
  3470.             fprintf(outputfile,"</I>");
  3471.             }
  3472.         if (inbold == 1)
  3473.             {
  3474.             inbold=0;
  3475.             fprintf(outputfile,"</B>");
  3476.             }
  3477.         if (inblink == 1)
  3478.             {
  3479.             inblink=0;
  3480.             fprintf(outputfile,"</BLINK>");
  3481.             }
  3482.         if (inafont)
  3483.             {
  3484.             fprintf(outputfile,"</FONT>");
  3485.             incolor[0] = '\0';
  3486.             currentfontcode=-1;
  3487.             }
  3488.         inafont =0;
  3489.         inacolor=0;
  3490.         currentfontsize=NORMAL;
  3491.         }
  3492.     error(erroroutput,"left end chp sucessfully\n");
  3493.     }
  3494.  
  3495.  
  3496. /*
  3497. letter logic:
  3498.     in comes letter, check the font stuff, if its some fonts it appears
  3499.     to be fSpec by default, then run through the fSpec code , then
  3500.     if it gets through that then if its a special font decode the char
  3501.     otherwise run it through the ordinary letter handling
  3502. */
  3503.  
  3504. int decode_letter(int letter,int flag,pap *apap, chp * achp,field_info *magic_fields,FILE *main,FILE *data,ffn *fontnamelist,list_info *a_list_info,textportions *portions, int *issection)
  3505.     {
  3506.     int ret=0;
  3507.     int i,j;
  3508.     static U8 fieldwas=-1;
  3509.     static int fieldeater=0;
  3510.     static long int swallowcp1=-1,swallowcp2=-1;
  3511.     static int spacecount;
  3512.     static int tabstop;
  3513.     static int silent=0;
  3514.     float tabbing;
  3515.     ffn *tempfont;
  3516.     time_t timep;
  3517.     struct tm *times;
  3518.     char date[1024];
  3519.     char *fontname=NULL;
  3520.     int fSpecflag=0;
  3521.     U16 temp=0;
  3522.     obj_by_spid *tempblip;
  3523.     char *tempname;
  3524.     
  3525.     static int fieldparse=0;
  3526.     U16 *array;
  3527.     U16 *array2;
  3528.     U16 *deleteme=NULL;
  3529.  
  3530.     long pictureoffset;
  3531.     U32 picturelen;
  3532.     U16 datatype;
  3533.     
  3534.     U8 target[7];
  3535.     int len;
  3536.  
  3537.     chp tempchp;
  3538.  
  3539.     int temp2;
  3540.  
  3541.     cellempty--;
  3542.  
  3543.     if (insuper==2)
  3544.         insuper=1;
  3545.  
  3546.     switch (fieldparse)    
  3547.         {
  3548.         case 37:
  3549.             realcp++;
  3550.             cp++;
  3551.             array = decode_crosslink(letter,&swallowcp1,&swallowcp2);
  3552.             if (array != NULL)
  3553.                 {
  3554.                 fprintf(outputfile,"<a href=\"#");
  3555.                 array2 = array;
  3556.                 while (*array2 != '\0')
  3557.                     { 
  3558.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  3559.                     fprintf(outputfile,"%c",*array2); 
  3560.                     array2++;
  3561.                     }
  3562.                 fprintf(outputfile,"\">*</a>");
  3563.                 fflush(outputfile);
  3564.                 error(erroroutput,"end of the mallocing\n");
  3565.                 free(array);
  3566.                 fieldparse=0;
  3567.                 }
  3568.             return(0);
  3569.             break;
  3570.         case 88:
  3571.             array = decode_hyperlink(letter,&swallowcp1,&swallowcp2,&deleteme);        
  3572.             realcp++;
  3573.             cp++;
  3574.  
  3575.             if (array == NULL)        /*if theres no letters for the rest of this guy to parse*/
  3576.                 return(0);
  3577.             else    
  3578.                 {
  3579.                 fieldparse=0;
  3580.                 array2 = array;
  3581.                 if (array2[0] != '\"')
  3582.                     fprintf(outputfile,"\"");
  3583.                 
  3584.                 while (*array2 != '\0')
  3585.                     {
  3586.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  3587.                     fprintf(outputfile,"%c",*array2); 
  3588.                     array2++;
  3589.                     }
  3590.                 array2--;
  3591.                 
  3592.                 if (*array2 != '\"')
  3593.                     fprintf(outputfile,"\"");
  3594.  
  3595.                 fprintf(outputfile,">");
  3596.  
  3597.                 
  3598.                 if (deleteme != NULL)
  3599.                     free(deleteme);
  3600.                     
  3601.                 return(0);
  3602.                 }
  3603.             break;
  3604.         default:
  3605.             break;
  3606.         }
  3607.  
  3608.     if  (letter != 13 || achp->fontcode !=0 ) 
  3609.         {
  3610.         if (flushbreaks(0))
  3611.             {
  3612.             error(erroroutput,"<!--new paragraph-->");
  3613.             do_indent(apap);
  3614.             }
  3615.         }
  3616.  
  3617.     if (fontnamelist != NULL)
  3618.         {
  3619.         if ( (achp->fontcode !=0) && (letter > 34) ) 
  3620.             {
  3621.             error(erroroutput,"asked for nonstandard font %d\n",achp->fontcode);
  3622. #if 0
  3623.             i=0;
  3624.             tempfont = fontnamelist;
  3625.             while (i < achp->fontcode)
  3626.                 {
  3627.                 tempfont = tempfont->next;
  3628.                 if (tempfont == NULL)
  3629.                     break;
  3630.                 i++;
  3631.                 }
  3632. #endif
  3633.             tempfont = get_fontnamefromcode(fontnamelist,achp->fontcode,&i);
  3634.             if (tempfont == NULL)
  3635.                 {
  3636.                 error(erroroutput,"warning!! fontcode incorrect, abandoning\n");
  3637.                 return(0);
  3638.                 }
  3639.  
  3640.             error(erroroutput,"i is %d and font is %s\n",i,tempfont->name);
  3641.             if (i == achp->fontcode)
  3642.                 {
  3643.                 if (!(strcmp("Symbol",tempfont->name)))
  3644.                     {
  3645.                     error(erroroutput,"must use symbol font for this letter\n");
  3646.                     if (decode_symbol(achp->fontspec))
  3647.                         {
  3648.                         cp++;
  3649.                         realcp++;
  3650.                         return(ret);
  3651.                         }
  3652.                     }
  3653.                 else if (!(strcmp("Wingdings",tempfont->name)))
  3654.                     {
  3655.                     error(erroroutput,"must use wingding font for this letter %c\n",letter);
  3656.                     if (decode_wingding(achp->fontspec))
  3657.                         {
  3658.                         cp++;
  3659.                         realcp++;
  3660.                         return(ret);
  3661.                         }
  3662.                     }
  3663.                 }
  3664.             }
  3665.         else 
  3666.             {
  3667. #if 0
  3668.             i=0;
  3669.             tempfont = fontnamelist;
  3670.             while (i < achp->ascii_font)
  3671.                 {
  3672.                 tempfont = tempfont->next;
  3673.                 if (tempfont == NULL)
  3674.                     break;
  3675.                 i++;
  3676.                 }
  3677. #endif
  3678.             tempfont = get_fontnamefromcode(fontnamelist,achp->ascii_font,&i);
  3679.             error(erroroutput,"i is %d and font is %s\n",i,tempfont->name);
  3680.             if ( (i == achp->ascii_font) && (letter > 34) ) 
  3681.                 {
  3682.                 if (!(strcmp("Symbol",tempfont->name)))
  3683.                     {
  3684.                     error(erroroutput,"must use symbol font for this letter here\n");
  3685.                     fontname=tempfont->name;
  3686.                     if (achp->fSpec==0)
  3687.                         {
  3688.                         achp->fSpec=1;
  3689.                         fSpecflag=1;
  3690.                         }
  3691.                     }
  3692.                 else if (!(strcmp("Wingdings",tempfont->name)))
  3693.                     {
  3694.                     error(erroroutput,"must use wingding font for this letter here %d fontcode is %d\n",letter,achp->fontcode);
  3695.                     fontname=tempfont->name;
  3696.                     if (achp->fSpec==0)
  3697.                         {
  3698.                         achp->fSpec=1;
  3699.                         fSpecflag=1;
  3700.                         }
  3701.                     }
  3702.                 }
  3703.  
  3704.             }
  3705.         }
  3706.  
  3707.     error(erroroutput,"cp is %x (%x) Trealcp is %x\n",cp,letter,realcp);
  3708.     if ( ( (fieldeater == 2) && (letter != 0x20) ) || ( (fieldeater > 0) && (letter == 0x20) ))
  3709.         {
  3710.         fieldeater--;
  3711.         if (fieldeater == 0)
  3712.             silent=0;
  3713.         }
  3714. #if 0
  3715.     else if ((cp > swallowcp1) && (cp < swallowcp2))
  3716.         {
  3717.         error(erroroutput,"swallowing %c\n",letter);
  3718.         }
  3719. #endif
  3720.     else
  3721.         {
  3722.         if ((letter != 32) && (spacecount == 1))
  3723.             {
  3724.             if (achp->underline == 2)
  3725.                 {
  3726.                 temp = achp->underline;
  3727.                 achp->underline=0;
  3728.                 decode_e_chp(achp);
  3729.                 decode_s_chp(achp,fontnamelist);
  3730.                 }
  3731.             oprintf(silent," ");
  3732.             if (temp == 2)
  3733.                 {
  3734.                 achp->underline=temp;
  3735.                 decode_e_chp(achp);
  3736.                 decode_s_chp(achp,fontnamelist);
  3737.                 }
  3738.             spacecount=0;
  3739.             tabstop++;
  3740.             }
  3741.         else if (letter != 32) 
  3742.             {
  3743.             if (i>0)
  3744.                 {
  3745.                 if (achp->underline == 2)
  3746.                     {
  3747.                     temp = achp->underline;
  3748.                     achp->underline=0;
  3749.                     decode_e_chp(achp);
  3750.                     decode_s_chp(achp,fontnamelist);
  3751.                     }
  3752.                 for (i=0;i<spacecount;i++)
  3753.                     {
  3754.                     if (padding < 3)
  3755.                         oprintf(silent," ");
  3756.                     tabstop++;
  3757.                     }
  3758.                 if (temp == 2)
  3759.                     {
  3760.                     achp->underline=temp;
  3761.                     decode_e_chp(achp);
  3762.                     decode_s_chp(achp,fontnamelist);
  3763.                     }
  3764.                 }
  3765.             spacecount=0;
  3766.             }
  3767.  
  3768.  
  3769.         tabstop++;
  3770.  
  3771.         if (achp->fSpec==1)
  3772.             {
  3773.             switch (letter)
  3774.                 {
  3775.                 case 0:
  3776.                     fprintf(outputfile,"%d",pagenumber);
  3777.                     error(erroroutput,"pagenumber is now %d\n",pagenumber);
  3778.                     break;
  3779.                 case 1:
  3780.                     if ((achp->fData == 0) && (achp->fOle2 == 0))
  3781.                         {
  3782.                         error(erroroutput,"handle picture\n");
  3783.                         error(erroroutput,"IN THIS CASE data offset is %x, ole2 is %x\n",achp->fcPic,achp->fOle2);
  3784.  
  3785.                         pictureoffset = get_picture_header(achp->fcPic,data,&picturelen,&datatype);
  3786.                         error(erroroutput,"the offset is %x, the len is %d\n",pictureoffset,picturelen);
  3787.                         if (datatype != 0x6400)
  3788.                             error(erroroutput,"data type isnt office draw, its %d (%x) ignoring\n",datatype,datatype);
  3789.                         else
  3790.                             {
  3791.                             if (picblips != NULL)
  3792.                                 error(erroroutput,"here we have %s\n",picblips->filename);
  3793.                             else
  3794.                                 error(erroroutput,"here we have NULL\n");
  3795.                             fflush(outputfile);
  3796.                             picblips = get_blips(pictureoffset,picturelen,data,data,&temp2,0x01,&picblips);
  3797.                             tempblip = picblips;
  3798.                             if (tempblip == NULL)
  3799.                                 error(erroroutput,"tempblip is NULL\n");
  3800.                             if (tempblip != NULL)
  3801.                                 {
  3802.                                 tempname = tempblip->filename;
  3803.                                 while (tempblip->next != NULL)
  3804.                                     {
  3805.                                     tempblip = tempblip->next;
  3806.                                     error(erroroutput,"the filename is %s\n",tempblip->filename);
  3807.                                     error(erroroutput,"the spid is %x\n",tempblip->spid);
  3808.                                     /*
  3809.                                     if ((tempblip->filename != NULL) && (tempblip->filename[0] != '\0'))
  3810.                                     */
  3811.                                     tempname = tempblip->filename;
  3812.                                     }
  3813.                                 outputimgsrc(tempname);
  3814.                                 }
  3815.                             }
  3816.                         }
  3817.                     break;
  3818.                 case 2:
  3819.                     if (inaheaderfooter!=1)
  3820.                         {
  3821.                         error(erroroutput,"INSERT REF\n");
  3822.                         decode_f_reference(portions);
  3823.                         }
  3824.                     break;
  3825.                 case 3:
  3826.                 case 4:
  3827.                     error(erroroutput,"do these matter in html mode\n");
  3828.                     break;
  3829.                 case 5:
  3830.                     error(erroroutput,"INSERT ANNOTATION\n");
  3831.                     if (doannos)
  3832.                         decode_annotation(portions,main);
  3833.                     break;
  3834.                 case 6:
  3835.                     error(erroroutput,"line no\n");
  3836.                     fprintf(outputfile,"UNKNOWN LINE NO\n");
  3837.                     break;
  3838.                 case 7:    
  3839.                     error(erroroutput,"what is this !, pen windowsn\n");
  3840.                     break;
  3841.                 case 8:    
  3842.                     error(erroroutput,"office draw thing, must get spid\n");
  3843.                     output_draw(cp,portions);
  3844.                     break;
  3845.                 case 10:
  3846.                     timep = time(NULL);
  3847.                     times = localtime(&timep);
  3848.                     strftime(date,1024,"%a, %b ",times);
  3849.                     error(erroroutput,"output date as %s\n",date);
  3850.                     fprintf(outputfile,"%s",date);
  3851.                     fprintf(outputfile,"%d",times->tm_mday);
  3852.                     strftime(date,1024,",%Y",times);
  3853.                     error(erroroutput,"output date as %s\n",date);
  3854.                     fprintf(outputfile,"%s",date);
  3855.                     break;
  3856.                 case 30:
  3857.                     timep = time(NULL);
  3858.                     times = localtime(&timep);
  3859.                     strftime(date,1024,"%x",times);
  3860.                     error(erroroutput,"output date as %s\n",date);
  3861.                     fprintf(outputfile,"%s",date);
  3862.                     break;
  3863.                 case 11:
  3864.                     timep = time(NULL);
  3865.                     times = localtime(&timep);
  3866.                     strftime(date,1024,"%H:%M:%S",times);
  3867.                     error(erroroutput,"output time as %s\n",date);
  3868.                     fprintf(outputfile,"%s",date);
  3869.                     break;
  3870.                 case 28:
  3871.                     timep = time(NULL);
  3872.                     times = localtime(&timep);
  3873.                     strftime(date,1024,"%X",times);
  3874.                     error(erroroutput,"output time as %s\n",date);
  3875.                     fprintf(outputfile,"%s",date);
  3876.                     break;
  3877.                 case 12:
  3878.                     fprintf(outputfile,"--%d--\n",sectionno);
  3879.                     error(erroroutput,"did section no\n");
  3880.                     break;
  3881.                 case 14:
  3882.                     timep = time(NULL);
  3883.                     times = localtime(&timep);
  3884.                     strftime(date,1024,"%a",times);
  3885.                     error(erroroutput,"output time as %s\n",date);
  3886.                     fprintf(outputfile,"%s",date);
  3887.                     break;
  3888.                 case 15:
  3889.                     timep = time(NULL);
  3890.                     times = localtime(&timep);
  3891.                     strftime(date,1024,"%A",times);
  3892.                     error(erroroutput,"output time as %s\n",date);
  3893.                     fprintf(outputfile,"%s",date);
  3894.                     break;
  3895.                 case 16:
  3896.                     timep = time(NULL);
  3897.                     times = localtime(&timep);
  3898.                     /*
  3899.                     strftime(date,1024,"%d",times);
  3900.                     error(erroroutput,"output time as %s\n",date);
  3901.                     */
  3902.                     fprintf(outputfile,"%d",times->tm_mday);
  3903.                     break;
  3904.                 case 22:
  3905.                     timep = time(NULL);
  3906.                     times = localtime(&timep);
  3907.                     /*
  3908.                     strftime(date,1024,"%H",times);
  3909.                     error(erroroutput,"output time as %s\n",date);
  3910.                     */
  3911.                     fprintf(outputfile,"%d",times->tm_hour);
  3912.                     break;
  3913.                 case 23:
  3914.                     timep = time(NULL);
  3915.                     times = localtime(&timep);
  3916.                     strftime(date,1024,"%H",times);
  3917.                     error(erroroutput,"output time as %s\n",date);
  3918.                     fprintf(outputfile,"%s",date);
  3919.                     break;
  3920.                 case 24:
  3921.                     timep = time(NULL);
  3922.                     times = localtime(&timep);
  3923.                     /*
  3924.                     strftime(date,1024,"%M",times);
  3925.                     error(erroroutput,"output time as %s\n",date);
  3926.                     */
  3927.                     fprintf(outputfile,"%d",times->tm_min);
  3928.                     break;
  3929.                 case 25:
  3930.                     timep = time(NULL);
  3931.                     times = localtime(&timep);
  3932.                     strftime(date,1024,"%M",times);
  3933.                     error(erroroutput,"output time as %s\n",date);
  3934.                     fprintf(outputfile,"%s",date);
  3935.                     break;
  3936.                 case 26:
  3937.                     timep = time(NULL);
  3938.                     times = localtime(&timep);
  3939.                     strftime(date,1024,"%S",times);
  3940.                     error(erroroutput,"output time as %s\n",date);
  3941.                     fprintf(outputfile,"%s",date);
  3942.                     break;
  3943.                 case 27:
  3944.                     timep = time(NULL);
  3945.                     times = localtime(&timep);
  3946.                     strftime(date,1024,"%p",times);
  3947.                     error(erroroutput,"output time as %s\n",date);
  3948.                     fprintf(outputfile,"%s",date);
  3949.                     break;
  3950.                 case 29:
  3951.                     timep = time(NULL);
  3952.                     times = localtime(&timep);
  3953.                     strftime(date,1024,"%B ",times);
  3954.                     error(erroroutput,"output time as %s\n",date);
  3955.                     fprintf(outputfile,"%s",date);
  3956.                     fprintf(outputfile,"%d",times->tm_mday);
  3957.                     strftime(date,1024,", %Y",times);
  3958.                     fprintf(outputfile,"%s",date);
  3959.                     break;
  3960.                 case 33:
  3961.                     timep = time(NULL);
  3962.                     times = localtime(&timep);
  3963.                     strftime(date,1024,"%m",times);
  3964.                     error(erroroutput,"output time as %s\n",date);
  3965.                     fprintf(outputfile,"%s",date);
  3966.                     break;
  3967.                 case 34:
  3968.                     timep = time(NULL);
  3969.                     times = localtime(&timep);
  3970.                     strftime(date,1024,"%Y",times);
  3971.                     error(erroroutput,"output time as %s\n",date);
  3972.                     fprintf(outputfile,"%s",date);
  3973.                     break;
  3974.                 case 35:
  3975.                     timep = time(NULL);
  3976.                     times = localtime(&timep);
  3977.                     strftime(date,1024,"%y",times);
  3978.                     error(erroroutput,"output time as %s\n",date);
  3979.                     fprintf(outputfile,"%s",date);
  3980.                     break;
  3981.                 case 36:
  3982.                     timep = time(NULL);
  3983.                     times = localtime(&timep);
  3984.                     strftime(date,1024,"%b",times);
  3985.                     error(erroroutput,"output time as %s\n",date);
  3986.                     fprintf(outputfile,"%s",date);
  3987.                     break;
  3988.                 case 37:
  3989.                     timep = time(NULL);
  3990.                     times = localtime(&timep);
  3991.                     strftime(date,1024,"%B",times);
  3992.                     error(erroroutput,"output time as %s\n",date);
  3993.                     fprintf(outputfile,"%s",date);
  3994.                     break;
  3995.                 case 38:
  3996.                     timep = time(NULL);
  3997.                     times = localtime(&timep);
  3998.                     strftime(date,1024,"%H:%M",times);
  3999.                     error(erroroutput,"output time as %s\n",date);
  4000.                     fprintf(outputfile,"%s",date);
  4001.                     break;
  4002.                 case 39:
  4003.                     timep = time(NULL);
  4004.                     times = localtime(&timep);
  4005.                     strftime(date,1024,"%A, %B, ",times);
  4006.                     fprintf(outputfile,"%s",date);
  4007.                     fprintf(outputfile,"%d, ",times->tm_mday);
  4008.                     strftime(date,1024,"%Y",times);
  4009.                     fprintf(outputfile,"%s",date);
  4010.                     break;
  4011.                 case 41:
  4012.                     error(erroroutput,"print merge ?\n");
  4013.                     break;
  4014.                 case 19:
  4015.                     error(erroroutput,"\nfield begins\n");
  4016.                     init_chp(&tempchp);
  4017.                     chpsoff();
  4018.                     decode_field(main,magic_fields,&cp,&fieldwas,&swallowcp1,&swallowcp2);
  4019.                     error(erroroutput,"cp vals are %x and %x\n",swallowcp1,swallowcp2);        /*if theres no letters for the rest of this guy to parse*/
  4020.  
  4021.                     switch (fieldwas)
  4022.                         {
  4023.                         case 37:
  4024.                             if ((swallowcp1 != -1) && (swallowcp2 != -1))
  4025.                                 fieldparse=37;
  4026.                             silent=1;
  4027.                             break;
  4028.                         case 88:
  4029.                             if ((swallowcp1 != -1) && (swallowcp2 != -1))
  4030.                                 fieldparse=88;
  4031.                             break;
  4032.                         default:
  4033.                             silent=1;
  4034.                             break;
  4035.                         }
  4036.                     break;
  4037.                 case 21:
  4038.                     error(erroroutput,"\nfield ends\n");
  4039.                     decode_field(main,magic_fields,&cp,&fieldwas,&swallowcp1,&swallowcp2);
  4040.                     chpson();
  4041.                     silent=0;
  4042.                     fieldparse=0;
  4043.                     break;
  4044.                 case 20:
  4045.                     error(erroroutput,"\n field separator\n");
  4046.                     decode_field(main,magic_fields,&cp,&fieldwas,&swallowcp1,&swallowcp2);
  4047.                     if ( (fieldwas == 10) || (fieldwas == 12) || (fieldwas == 68) || (fieldwas == 17) || (fieldwas == 29) || (fieldwas == 13) || (fieldwas == 88) || (fieldwas == 3))
  4048.                         {
  4049.                         silent=0;
  4050.                         chpson();
  4051.                         }
  4052.                     break;
  4053.                 default:
  4054.                     if (fontname==NULL)
  4055.                         {
  4056.                         if (flag)
  4057.                             {
  4058.                             len = our_wctomb(target,letter);
  4059.                             error(erroroutput,"letter3: %x %d",letter,letter);
  4060.                             /*
  4061.                             expand this in the ranges that we will have to handle 
  4062.                             ourselves, just for my own benefit for now, i might be
  4063.                             able to build a table with some word macros and luck*/
  4064.                             if (letter == 0x2122)
  4065.                                 decode_symbol(0xf0e4);
  4066.                             else if (letter != 0)
  4067.                                 for(i=0;i<len;i++)
  4068.                                     {
  4069.                                     if ( (achp->fSmallCaps || achp->fCaps)  && use_fontfacequery(achp) && (len == 1) )
  4070.                                         {
  4071.                                         if  ( isupper(target[i]) && achp->fSmallCaps)
  4072.                                             {
  4073.                                             temp = achp->fontsize;
  4074.                                             achp->fontsize+=2;
  4075.                                             decode_e_chp(achp);
  4076.                                             decode_s_chp(achp,fontnamelist);
  4077.                                             achp->fontsize = temp;
  4078.                                             }
  4079.                                         target[i] = toupper(target[i]);
  4080.                                         }
  4081.                                     oprintf(silent,"%c",target[i]);
  4082.  
  4083.                                     error(erroroutput,"letter2: %c, silent is %d",target[i],silent);
  4084.                                     }
  4085.                             else
  4086.                                 error(erroroutput,"given 0 as a letter !\n");
  4087.                             }
  4088.                         else
  4089.                             {
  4090.                             if (letter == 0xae)
  4091.                                 decode_symbol(61666);
  4092.                             else if (letter != 0)
  4093.                                 {
  4094.                                 if ( ( achp->fSmallCaps || achp->fCaps) && use_fontfacequery(achp) )
  4095.                                     {
  4096.                                     if  ( letter && achp->fSmallCaps)
  4097.                                             {
  4098.                                             temp = achp->fontsize;
  4099.                                             achp->fontsize+=2;
  4100.                                             decode_e_chp(achp);
  4101.                                             decode_s_chp(achp,fontnamelist);
  4102.                                             achp->fontsize = temp;
  4103.                                             }
  4104.                                     letter = toupper(letter);
  4105.                                     }
  4106.                                 oprintf(silent,"%c",letter);
  4107.                                 }
  4108.                             error(erroroutput,"letter2: %c %d %x, silent is %d",letter,letter,letter,silent);
  4109.                             }
  4110.                         }
  4111.                     else
  4112.                         {
  4113.                         if (!(strcmp("Wingdings",fontname)))
  4114.                             decode_wingding(letter);
  4115.                         else if (!(strcmp("Symbol",fontname)))
  4116.                             decode_symbol(letter);
  4117.                         realcp++;
  4118.                         cp++;
  4119.                         if (fSpecflag)
  4120.                             achp->fSpec=0;
  4121.                         return(ret);
  4122.                         }
  4123.                     break;
  4124.                 }
  4125.             }
  4126.         else
  4127.             {
  4128.             switch(letter)
  4129.                 {
  4130.                 case 13:
  4131.                     error(erroroutput,"\n<!--paragraph end-->\n");
  4132.                     if (!silent)
  4133.                         {
  4134.                         breakcount++;
  4135.  
  4136.                         if (cellempty == 0)
  4137.                             cellempty++;
  4138.                         
  4139.                         tabstop=0;
  4140.                         newline=1;
  4141.                         }
  4142.                     break;
  4143.                 case 11:
  4144.                     error(erroroutput,"\n(--line break--)\n");
  4145.                     oprintf(silent,"<BR>\n");
  4146.                     tabstop=0;
  4147.                     break;
  4148.                 case 45:
  4149.                     error(erroroutput,"-");
  4150.                     oprintf(silent,"-"); 
  4151.                     break;
  4152.                 case 32:
  4153.                     spacecount++;
  4154.                     tabstop--;
  4155.                     if (cellempty == 0)
  4156.                         cellempty++;
  4157.                     break;
  4158.                 case 31:
  4159.                     error(erroroutput,"\n(-nonrequired hyphen- ?)\n");
  4160.                     oprintf(silent,"-");
  4161.                     break;
  4162.                 case 30:
  4163.                     error(erroroutput,"\n(-nonbreaking hyphen- ?)\n");
  4164.                     oprintf(silent,"-");
  4165.                     break;
  4166.                 case 160:
  4167.                     error(erroroutput,"\n(-non breaking space)\n");
  4168.                     oprintf(silent," ");
  4169.                     break;
  4170.                 case 12:
  4171.                     error(erroroutput,"\npage break (maybe section) at %x\n",cp);
  4172.                     for (i=0;i<portions->section_nos+1;i++)
  4173.                         {
  4174.                         if (cp+1 == portions->section_cps[i])
  4175.                             {
  4176.                             /*sectionpagenumber=1;*/
  4177.                             sectionno++;
  4178.                             *issection=1;
  4179.                             }
  4180.                         }
  4181.                     ret=1;
  4182.                     tabstop=0;
  4183.                     break;
  4184.                 case 14:
  4185.                     error(erroroutput,"\ncolumn break\n");
  4186.                     columnbreak();
  4187.                     break;
  4188.                 case 9:
  4189.                     tabstop--;
  4190.                     error(erroroutput,"\ntab\n");
  4191.                     tabbing = ((float)tabstop)/8;
  4192.                     error(erroroutput,"tabbing is %f, from %d\n",tabbing,tabstop);
  4193.                     error(erroroutput,"tabsize is %f\n",tabsize);
  4194.                     if (tabbing == tabstop/8)
  4195.                         {
  4196.                         if ( (padding == 0) || (padding == 3))
  4197.                             fprintf(outputfile,"<img height=1 width=%d src=\"%s/clear.gif\">",(int)(8*tabsize),patterndir());
  4198.                         else if ( (padding == 1) || (padding == 4))
  4199.                             for(j=0;j<(int)tabsize;j++)
  4200.                                 oprintf(silent," ");
  4201.                         else if ( (padding == 5) || (padding == 2))
  4202.                             oprintf(silent," ");
  4203.                         tabstop = tabstop=8;
  4204.                         }
  4205.                     else 
  4206.                         {
  4207.                         temp2 = (8-((tabbing - (tabstop/8))*8))+1;
  4208.                         error(erroroutput,"temp2 is %d\n",temp2);
  4209.                         if ( (padding == 1) || (padding == 4))
  4210.                             {
  4211.                             for(i=0;i< (8-((tabbing - (tabstop/8))*8))+1;i++)
  4212.                                     for(j=0;j<(int)(tabsize/8);j++)
  4213.                                         oprintf(silent," ");
  4214.                             }
  4215.                         else if ( (padding == 0) || (padding == 3))
  4216.                             fprintf(outputfile,"<img height=1 width=%d src=\"%s/clear.gif\">",(int)(temp2*tabsize),patterndir());
  4217.                         else if ((padding == 5) || (padding == 2))
  4218.                             oprintf(silent," ");
  4219.                         tabstop = tabstop+(8-(tabbing - (tabstop/8))*8);
  4220.                         }
  4221.                     /*oprintf(silent,"<TAB>");*/
  4222.                     break;
  4223.                 case 19:
  4224.                     error(erroroutput,"\nfield begins\n");
  4225.                     init_chp(&tempchp);
  4226.                     chpsoff();
  4227.                     decode_field(main,magic_fields,&cp,&fieldwas,&swallowcp1,&swallowcp2);
  4228.                     error(erroroutput,"cp vals are %x and %x\n",swallowcp1,swallowcp2);
  4229.                     switch (fieldwas)
  4230.                         {
  4231.                         case 37:
  4232.                             if ((swallowcp1 != -1) && (swallowcp2 != -1))
  4233.                                 fieldparse=37;
  4234.                             break;
  4235.                         case 88:
  4236.                             if ((swallowcp1 != -1) && (swallowcp2 != -1))
  4237.                                 fieldparse=88;
  4238.                             break;
  4239.                         default:
  4240.                             silent=1;
  4241.                             break;
  4242.                         }
  4243.                     break;
  4244.                 case 21:
  4245.                     error(erroroutput,"\nfield ends\n");
  4246.                     decode_field(main,magic_fields,&cp,&fieldwas,&swallowcp1,&swallowcp2);
  4247.                     chpson();
  4248.                     silent=0;
  4249.                     fieldparse=0;
  4250.                     break;
  4251.                 case 20:
  4252.                     error(erroroutput,"\n field separator\n");
  4253.                     decode_field(main,magic_fields,&cp,&fieldwas,&swallowcp1,&swallowcp2);
  4254.                     if ( (fieldwas == 10) || (fieldwas == 12) || (fieldwas == 68) || (fieldwas == 17) || (fieldwas == 29) || (fieldwas == 13) || (fieldwas == 88) || (fieldwas == 3))
  4255.                         {
  4256.                         silent=0;
  4257.                         chpson();
  4258.                         }
  4259.                     break;
  4260.                 case '<':
  4261.                     oprintf(silent,"<");
  4262.                     break;
  4263.                 case '>':
  4264.                     oprintf(silent,">");
  4265.                     break;
  4266.                 case 7:
  4267.                     if (cellempty == 0)
  4268.                         cellempty++;
  4269.                     apap->tableflag=1;
  4270.                     decode_e_specials(apap,achp,a_list_info);
  4271.                     if (decode_e_table(apap,achp,a_list_info)==1)
  4272.                         {
  4273.                         if (deferrednewpage)
  4274.                             {
  4275.                             deferrednewpage=0;
  4276.                             ret=2;
  4277.                             }
  4278.                         }
  4279.                     error(erroroutput,"\n");
  4280.                     newline=1;
  4281.                     break;
  4282.                 case 0x96:
  4283.                 case 0x2013:
  4284.                     oprintf(silent,"-");
  4285.                     break;
  4286.                 case 145:
  4287.                 case 146:
  4288.                     oprintf(silent,"'");
  4289.                     break;
  4290.                 case 132:
  4291.                 case 147:
  4292.                     error(erroroutput,"begin quot\n");
  4293.                     oprintf(silent,""");
  4294.                     break;
  4295.                 case 148:
  4296.                     error(erroroutput,"end quot\n");
  4297.                     oprintf(silent,""");
  4298.                     break;
  4299.                 case 0x85:
  4300.                     if (flag)
  4301.                         letter = 0x2026;
  4302.                     else
  4303.                         {
  4304.                         fontname = "Symbol";
  4305.                         letter = 0xf0bc;
  4306.                         /*156.gif*/
  4307.                         }
  4308.                     /*deliberate fallthrough*/
  4309.                 default:
  4310.                     if (fontname==NULL)
  4311.                         {
  4312.                         if (flag)
  4313.                             {
  4314.                             len = our_wctomb(target,letter);
  4315.                             error(erroroutput,"letter3: %x %d",letter,letter);
  4316.                             /*
  4317.                             expand this in the ranges that we will have to handle 
  4318.                             ourselves, just for my own benefit for now, i might be
  4319.                             able to build a table with some word macros and luck*/
  4320.                             if (letter == 0x2122)
  4321.                                 decode_symbol(0xf0e4);
  4322.                             else if (letter != 0)
  4323.                                 for(i=0;i<len;i++)
  4324.                                     {
  4325.                                     if ( (achp->fSmallCaps || achp->fCaps) && use_fontfacequery(achp) && (len == 1) )
  4326.                                         {
  4327.                                         if  ( isupper(target[i]) && achp->fSmallCaps)
  4328.                                                 {
  4329.                                                 temp = achp->fontsize;
  4330.                                                 achp->fontsize+=2;
  4331.                                                 decode_e_chp(achp);
  4332.                                                 decode_s_chp(achp,fontnamelist);
  4333.                                                 achp->fontsize = temp;
  4334.                                                 }
  4335.                                         target[i] = toupper(target[i]);
  4336.                                         }
  4337.                                     oprintf(silent,"%c",target[i]);
  4338.                                     error(erroroutput,"letter2: %c, silent is %d",target[i],silent);
  4339.                                     }
  4340.                             else
  4341.                                 error(erroroutput,"given 0 as a letter !\n");
  4342.                             }
  4343.                         else
  4344.                             {
  4345.                             if (letter == 0xae)
  4346.                                 decode_symbol(61666);
  4347.                             else if (letter != 0)
  4348.                                 {
  4349.                                 if ( (achp->fSmallCaps || achp->fCaps) && (use_fontfacequery(achp)) )
  4350.                                     {
  4351.                                     if  ( isupper(letter) && achp->fSmallCaps)
  4352.                                             {
  4353.                                             temp = achp->fontsize;
  4354.                                             achp->fontsize+=2;
  4355.                                             decode_e_chp(achp);
  4356.                                             decode_s_chp(achp,fontnamelist);
  4357.                                             achp->fontsize = temp;
  4358.                                             }
  4359.                                     letter = toupper(letter);
  4360.                                     }
  4361.                                 oprintf(silent,"%c",letter);
  4362.                                 }
  4363.                             else
  4364.                                 error(erroroutput,"silly 0 found\n");
  4365.                             error(erroroutput,"letter2: %c %d %x silent is %d",letter,letter,letter,silent);
  4366.                             }
  4367.                         }
  4368.                     else
  4369.                         {
  4370.                         if (!(strcmp("Wingdings",fontname)))
  4371.                             decode_wingding(letter);
  4372.                         else if (!(strcmp("Symbol",fontname)))
  4373.                             decode_symbol(letter);
  4374.                         realcp++;
  4375.                         cp++;
  4376.                         if (fSpecflag)
  4377.                             achp->fSpec=0;
  4378.                         return(ret);
  4379.                         }
  4380.                     break;
  4381.                 }
  4382.                 
  4383.             }
  4384.         }
  4385.     cp++;
  4386.     realcp++;
  4387.     return(ret);
  4388.     }
  4389.  
  4390.  
  4391. int decode_clx_endnote(U32 *rgfc,sep *asep,int nopieces,U32 startpiece,U32 begincp,U32 endcp,FILE *in,FILE *main,FILE *data,U32 fcClx,U32 lcbClx,U32 intervals,U32 chpintervals,U32 *plcfbtePapx,U32 *plcfbteChpx,field_info *all_fields[5],list_info *a_list_info,style *sheet,textportions *portions,ffn *fontnamelist,int headerfooterflag)
  4392.     {
  4393.     U32 oldtablepos;
  4394.     U32 oldmainpos;
  4395.     U32 tempcp;
  4396.     U32 begin=0;
  4397.     U32 len=0;
  4398.     int k;
  4399.     field_info *tempfields;
  4400.     int i;
  4401.     chp achp;
  4402.     pap indentpap;
  4403.     int anyendnotes=0;
  4404.     char roman[81];
  4405.  
  4406.     flushbreaks(0);
  4407.     init_pap(&indentpap);
  4408.     do_indent(&indentpap);
  4409.  
  4410.     if (noheaders)
  4411.         return(anyendnotes);
  4412.  
  4413.     error(erroroutput,"list_end_no is %d\n",portions->list_end_no);
  4414.  
  4415.     if (header == 0)
  4416.         {
  4417.         for (i=0;i<portions->list_end_no;i++)
  4418.             {
  4419.             decode_endnote(&begin,&len,portions,i);
  4420.  
  4421.             if ((begin != -1) && (len != -1))
  4422.                 {
  4423.                 if (anyendnotes==0)
  4424.                     fprintf(outputfile,"\n<br><img src=\"%s/endnotebegin.gif\"><br>\n",patterndir());
  4425.                 anyendnotes++;
  4426.                 init_chp(&achp);
  4427.                 decode_s_chp(&achp,fontnamelist);
  4428.  
  4429.  
  4430.                 error(erroroutput,"beginning endnote\n");
  4431.                 /*test*/
  4432.                 fprintf(outputfile,"<p>");
  4433.                 fprintf(outputfile,"<font color=\"#330099\">");
  4434.                 inafont=1;
  4435.                 inacolor=1;
  4436.                 strcpy(incolor,"#330099");
  4437.                 /*end test*/
  4438.                 if (!insuper)
  4439.                     {
  4440.                     fprintf(outputfile,"<sup>");
  4441.                     insuper=2;
  4442.                     }
  4443.                 fprintf(outputfile,"<a name=\"end%d\">",i);
  4444.  
  4445.                 if (portions->endFRD[i] > 0)
  4446.                     {
  4447.                     /*
  4448.                     fprintf(outputfile,"%d",portions->endFRD[i]);
  4449.                     */
  4450.                     fprintf(outputfile,"%s",ms_strlower(decimalToRoman(portions->endTrueFRD[i],roman)));
  4451.                     fprintf(outputfile,"</A>");
  4452.                     if (insuper == 2)
  4453.                         {
  4454.                         fprintf(outputfile,"</sup>");
  4455.                         insuper=0;
  4456.                         }
  4457.                     }
  4458.                 else
  4459.                      footnotehack=1;
  4460.  
  4461.  
  4462.                 oldmainpos = ftell(main);
  4463.                 oldtablepos = ftell(in);
  4464.                 header++;
  4465.  
  4466.                 k=0;
  4467.                 while (k< nopieces)
  4468.                     {
  4469.                     if (portions->ccpText+portions->ccpFtn+portions->ccpHdd+portions->ccpAtn+begin < rgfc[k]) 
  4470.                         {
  4471.                         error(erroroutput,"piece for footer is %d (%x) (%x)\n",k-1,rgfc[k-1],portions->ccpText+begin);
  4472.                         break;
  4473.                         }
  4474.                     k++;
  4475.                     }
  4476.                 tempcp=cp;
  4477.                 cp=begin;
  4478.                 error(erroroutput,"the difference is %d\n",(portions->ccpText+begin)-rgfc[k-1]);
  4479.                 cp = rgfc[k-1];
  4480.                 error(erroroutput,"endnote len is %d\n",len);
  4481.                 error(erroroutput,"endnote cp is %x\n",cp);
  4482.                 tempfields = all_fields[0];
  4483.                 all_fields[0] = all_fields[4];
  4484.                 begin = portions->ccpText+portions->ccpFtn+portions->ccpHdd+portions->ccpAtn+begin;
  4485.                 error(erroroutput,"endnote begin cp is %d, begin is %d, end is %d\n",cp,begin,begin+len);
  4486.                 decode_clx(k-1,begin,begin+len,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,1);
  4487.                 if (footnotehack == 1)
  4488.                     {
  4489.                     fprintf(outputfile,"</A>");
  4490.                     footnotehack=0;
  4491.                     }
  4492.                 all_fields[0] = tempfields;
  4493.                 cp=tempcp;
  4494.                 fseek(in,oldtablepos,SEEK_SET);
  4495.                 fseek(main,oldmainpos,SEEK_SET);
  4496.                 header--;
  4497.                 }
  4498.             }
  4499.         portions->list_end_no=0; /*ready for next section endnotes*/
  4500.         error(erroroutput,"ending endnote\n");
  4501.  
  4502.         init_chp(&achp);
  4503.         decode_s_chp(&achp,fontnamelist);
  4504.         }
  4505.     return(anyendnotes);
  4506.     }
  4507.  
  4508. void decode_clx_footer(U32 *rgfc,sep *asep,int nopieces,U32 startpiece,U32 begincp,U32 endcp,FILE *in,FILE *main,FILE *data,U32 fcClx,U32 lcbClx,U32 intervals,U32 chpintervals,U32 *plcfbtePapx,U32 *plcfbteChpx,field_info *all_fields[5],list_info *a_list_info,style *sheet,textportions *portions,ffn *fontnamelist,int headerfooterflag)
  4509.     {
  4510.     U32 oldtablepos;
  4511.     U32 oldmainpos;
  4512.     U32 tempcp;
  4513.     U32 begin=0;
  4514.     U32 len=0;
  4515.     int k;
  4516.     field_info *tempfields;
  4517.     int i,j;
  4518.     int footnoteflag=0;
  4519.     int annotationflag=0;
  4520.     chp achp;
  4521.     pap indentpap;
  4522.  
  4523.     flushbreaks(0);
  4524.     init_pap(&indentpap);
  4525.     do_indent(&indentpap);
  4526.  
  4527.     if (noheaders)
  4528.         return;
  4529.  
  4530.     if (header == 0)
  4531.         {
  4532.         for (i=portions->last_foot;i<portions->list_foot_no+portions->last_foot;i++)
  4533.             {
  4534.             decode_footnote(&begin,&len,portions,i);
  4535.  
  4536.             if ((begin != -1) && (len != -1))
  4537.                 {
  4538.                 init_chp(&achp);
  4539.                 decode_s_chp(&achp,fontnamelist);
  4540.  
  4541.                 if (footnoteflag == 0)
  4542.                     {
  4543.                     fprintf(outputfile,"\n<br><img src=\"%s/footnotebegin.gif\"><br>\n",patterndir());
  4544.                     footnoteflag=1;
  4545.                     }
  4546.                 error(erroroutput,"beginning footnote\n");
  4547.                 /*test*/
  4548.                 fprintf(outputfile,"<p>");
  4549.                 fprintf(outputfile,"<font color=\"#330099\">");
  4550.                 inafont=1;
  4551.                 inacolor=1;
  4552.                 strcpy(incolor,"#330099");
  4553.                 /*end test*/
  4554.                 if (!insuper)
  4555.                     {
  4556.                     fprintf(outputfile,"<sup>");
  4557.                     insuper=2;
  4558.                     }
  4559.                     /*fish*/
  4560.                 fprintf(outputfile,"<a name=\"foot%d\">",i);
  4561.                     /*
  4562.                 fprintf(outputfile,"<a name=\"foot%d\">",portions->list_footnotes[i]);
  4563.                     */
  4564.  
  4565.                 if (portions->fndFRD[i] > 0)
  4566.                     {
  4567.                     fprintf(outputfile,"%d",portions->fndFRD[i]);
  4568.                     fprintf(outputfile,"</A>");
  4569.                     if (insuper == 2)
  4570.                         {
  4571.                         fprintf(outputfile,"</Sup>");
  4572.                         insuper=0;
  4573.                         }
  4574.                     }
  4575.                 else
  4576.                      footnotehack=1;
  4577.  
  4578.  
  4579.                 oldmainpos = ftell(main);
  4580.                 oldtablepos = ftell(in);
  4581.                 header++;
  4582.  
  4583.                 k=0;
  4584.                 while (k< nopieces)
  4585.                     {
  4586.                     if (portions->ccpText+begin < rgfc[k]) 
  4587.                         {
  4588.                         error(erroroutput,"piece for footer is %d (%x) (%x)\n",k-1,rgfc[k-1],portions->ccpText+begin);
  4589.                         break;
  4590.                         }
  4591.                     k++;
  4592.                     }
  4593.                 tempcp=cp;
  4594.                 cp=begin;
  4595.                 error(erroroutput,"the difference is %d\n",(portions->ccpText+begin)-rgfc[k-1]);
  4596.                 /*
  4597.                 cp = cp-((portions->ccpText+begin)-rgfc[k-1]);
  4598.                 */
  4599.                 cp = rgfc[k-1];
  4600.                 error(erroroutput,"footer len is %d\n",len);
  4601.                 error(erroroutput,"footer cp is %x\n",cp);
  4602.                 tempfields = all_fields[0];
  4603.                 all_fields[0] = all_fields[2];
  4604.                 begin = portions->ccpText+begin;
  4605.                 decode_clx(k-1,begin,begin+len,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,2);
  4606.                 if (footnotehack == 1)
  4607.                     {
  4608.                     fprintf(outputfile,"</A>");
  4609.                     footnotehack=0;
  4610.                     }
  4611.                 all_fields[0] = tempfields;
  4612.                 cp=tempcp;
  4613.                 fseek(in,oldtablepos,SEEK_SET);
  4614.                 fseek(main,oldmainpos,SEEK_SET);
  4615.                 header--;
  4616.                 }
  4617.             }
  4618.         portions->last_foot+=portions->list_foot_no;
  4619.         portions->list_foot_no=0; /*ready for next page footnotes*/
  4620.         portions->auto_foot=1;
  4621.  
  4622.         if (footnoteflag != 0)
  4623.             {
  4624.             fprintf(outputfile,"\n<br><img src=\"%s/footnoteend.gif\"><br>\n",patterndir());
  4625.             }
  4626.  
  4627. /*begin annotation*/
  4628.         for (i=portions->last_anno;i<portions->list_anno_no+portions->last_anno;i++)
  4629.             {
  4630.             decode_footanno(&begin,&len,portions,i);
  4631.  
  4632.             init_chp(&achp);
  4633.             decode_s_chp(&achp,fontnamelist);
  4634.  
  4635.             if ((begin != -1) && (len != -1))
  4636.                 {
  4637.                 if (annotationflag == 0)
  4638.                     {
  4639.                     fprintf(outputfile,"\n<br><img src=\"%s/commentbegin.gif\"><br>\n",patterndir());
  4640.                     annotationflag=1;
  4641.                     }
  4642.                 error(erroroutput,"beginning annotation\n");
  4643.                 /*test*/
  4644.                 fprintf(outputfile,"<font color=#ff7777>");
  4645.                 inafont=1;
  4646.                 inacolor=1;
  4647.                 strcpy(incolor,"#ff7777");
  4648.                 /*end test*/
  4649.  
  4650.                 if (!insuper)
  4651.                     fprintf(outputfile,"<sup>");
  4652.  
  4653.                 /*
  4654.                 fprintf(outputfile,"<a name=\"anno%d\">",i);
  4655.                 */
  4656.                 fprintf(outputfile,"<a name=\"");
  4657.                 j = portions->the_atrd[i].xstUsrInitl[0];
  4658.                 for (j=1;j<portions->the_atrd[i].xstUsrInitl[0]+1;j++)
  4659.                     {
  4660.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  4661.                     fprintf(outputfile,"%c",portions->the_atrd[i].xstUsrInitl[j]);
  4662.                     }
  4663.                 fprintf(outputfile,"%d",i);
  4664.                 fprintf(outputfile,"\">");
  4665.                 list_author_key=1;
  4666.                 j = portions->the_atrd[i].xstUsrInitl[0];
  4667.                 for (j=1;j<portions->the_atrd[i].xstUsrInitl[0]+1;j++)
  4668.                     {
  4669.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  4670.                     fprintf(outputfile,"%c",portions->the_atrd[i].xstUsrInitl[j]);
  4671.                     }
  4672.                 fprintf(outputfile,"%d",i+1);
  4673.                 /*
  4674.                 fprintf(outputfile,"anno%d",i);
  4675.                 */
  4676.  
  4677.                 fprintf(outputfile,"</a>");
  4678.                 if (!insuper)
  4679.                     fprintf(outputfile,"</sup>");
  4680.  
  4681.                 oldmainpos = ftell(main);
  4682.                 oldtablepos = ftell(in);
  4683.                 header++;
  4684.  
  4685.                 k=0;
  4686.                 while (k< nopieces)
  4687.                     {
  4688.                     if (portions->ccpText+portions->ccpFtn + portions->ccpHdd+begin < rgfc[k]) 
  4689.                         {
  4690.                         error(erroroutput,"piece for footer is %d (%x) (%x)\n",k-1,rgfc[k-1],portions->ccpText+portions->ccpFtn + portions->ccpHdd+begin);
  4691.                         break;
  4692.                         }
  4693.                     k++;
  4694.                     }
  4695.                 tempcp=cp;
  4696.                 cp=begin;
  4697.                 error(erroroutput,"the difference is %d\n",(portions->ccpText+portions->ccpFtn + portions->ccpHdd+begin)-rgfc[k-1]);
  4698.                 cp = cp-((portions->ccpText+portions->ccpFtn + portions->ccpHdd+begin)-rgfc[k-1]);
  4699.                 error(erroroutput,"footer len is %d\n",len);
  4700.                 error(erroroutput,"footer cp is %x\n",cp);
  4701.                 tempfields = all_fields[0];
  4702.                 all_fields[0] = all_fields[3];
  4703.                 decode_clx(k-1,begin,begin+len,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,3);
  4704.                 all_fields[0] = tempfields;
  4705.                 cp=tempcp;
  4706.                 fseek(in,oldtablepos,SEEK_SET);
  4707.                 fseek(main,oldmainpos,SEEK_SET);
  4708.                 header--;
  4709.                 }
  4710.             }
  4711.         if (annotationflag)
  4712.             fprintf(outputfile,"\n<br><img src=\"%s/commentbegin.gif\"><br>\n",patterndir());
  4713.             
  4714.         portions->last_anno+=portions->list_anno_no;
  4715.         portions->list_anno_no=0; /*ready for next page footnotes*/
  4716. /*end annotation*/        
  4717.         decode_footer(&begin,&len,portions,asep);
  4718.         if ((begin != -1) && (len != -1))
  4719.             {
  4720.             init_chp(&achp);
  4721.             decode_s_chp(&achp,fontnamelist);
  4722.  
  4723.             header++;
  4724.             error(erroroutput,"doing footer\n");
  4725.  
  4726.             oldmainpos = ftell(main);
  4727.             oldtablepos = ftell(in);
  4728.             error(erroroutput,"decoding footer clx 1\n");
  4729.             error(erroroutput,"the cp of begin of the header is probably cps (%x) to (%x)", portions->ccpText,portions->ccpText+portions->ccpFtn+portions->ccpHdd);
  4730.             k=0;
  4731.             while (k< nopieces)
  4732.                 {
  4733.                 if (portions->ccpText+portions->ccpFtn+begin < rgfc[k]) 
  4734.                     {
  4735.                     error(erroroutput,"piece for this footer is %d (%x) (%x)\n",k-1,rgfc[k-1],portions->ccpText+portions->ccpFtn+begin);
  4736.                     break;
  4737.                     }
  4738.                 k++;
  4739.                 }
  4740.             tempcp=cp;
  4741.             cp=begin;
  4742.             error(erroroutput,"the difference is %d\n",(portions->ccpText+portions->ccpFtn+begin)-rgfc[k-1]);
  4743.             cp = cp-((portions->ccpText+portions->ccpFtn+begin)-rgfc[k-1]);
  4744.             error(erroroutput,"footer len is %d\n",len);
  4745.             error(erroroutput,"footer cp is %x\n",cp);
  4746.             tempfields = all_fields[0];
  4747.             all_fields[0] = all_fields[1];
  4748.             inaheaderfooter=1;
  4749.             decode_clx(k-1,begin,begin+len,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,1);
  4750.             inaheaderfooter=0;
  4751.             all_fields[0] = tempfields;
  4752.             cp = tempcp;
  4753.             realcp = tempcp;
  4754.             fseek(in,oldtablepos,SEEK_SET);
  4755.             fseek(main,oldmainpos,SEEK_SET);
  4756.             header--;
  4757.             }
  4758.         error(erroroutput,"ending footer\n");
  4759.         pagenumber++;
  4760.         sectionpagenumber++;
  4761.         init_chp(&achp);
  4762.         decode_s_chp(&achp,fontnamelist);
  4763.         }
  4764.     }
  4765.  
  4766. void decode_clx_header(U32 *rgfc,sep *asep,int nopieces,U32 startpiece,U32 begincp,U32 endcp,FILE *in,FILE *main,FILE *data,U32 fcClx,U32 lcbClx,U32 intervals,U32 chpintervals,U32 *plcfbtePapx,U32 *plcfbteChpx,field_info *all_fields[5],list_info *a_list_info,style *sheet,textportions *portions,ffn *fontnamelist,int headerfooterflag)
  4767.     {
  4768.     U32 oldtablepos;
  4769.     U32 oldmainpos;
  4770.     U32 tempcp;
  4771.     U32 begin=0;
  4772.     U32 len=0;
  4773.     int k;
  4774.     field_info *tempfields;
  4775.  
  4776.     if (noheaders)
  4777.         return;
  4778.  
  4779.     if (header == 0)
  4780.         {
  4781.         decode_header(&begin,&len,portions,asep);
  4782.         if ((begin != -1) && (len != -1))
  4783.             {
  4784.             header++;
  4785.             oldmainpos = ftell(main);
  4786.             oldtablepos = ftell(in);
  4787.             error(erroroutput,"decoding header\n");
  4788.             error(erroroutput,"the cp of begin of the header is probably cps (%x) to (%x)", portions->ccpText+portions->ccpFtn+begin,portions->ccpText+portions->ccpFtn+begin+len);
  4789.             k=0;
  4790.             while (k< nopieces)
  4791.                 {
  4792.                 if (portions->ccpText+portions->ccpFtn+begin < rgfc[k]) 
  4793.                     {
  4794.                     error(erroroutput,"piece for header is %d (%x) (%x)\n",k-1,rgfc[k-1],portions->ccpText+portions->ccpFtn+begin);
  4795.                     break;
  4796.                     }
  4797.                 k++;
  4798.                 }
  4799.             tempcp=cp;
  4800.             cp=begin;
  4801.             cp = rgfc[k-1];
  4802.             error(erroroutput,"header cp is %x\n",cp);
  4803.             tempfields = all_fields[0];
  4804.             all_fields[0] = all_fields[1];
  4805.             begin = portions->ccpText+portions->ccpFtn+begin;
  4806.             inaheaderfooter=1;
  4807.             decode_clx(k-1,begin,begin+len,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,1);
  4808.             inaheaderfooter=0;
  4809.             all_fields[0] = tempfields;
  4810.             cp = tempcp;
  4811.             fseek(in,oldtablepos,SEEK_SET);
  4812.             fseek(main,oldmainpos,SEEK_SET);
  4813.             header--;
  4814.             }
  4815.         }
  4816.     }
  4817.  
  4818. int find_piece_cp(U32 sepcp,U32  *rgfc,int nopieces)
  4819.     {
  4820.     int i;
  4821.     error(erroroutput,"find_piece_cp-> %x,\n",sepcp);
  4822.     for (i=0;i<nopieces;i++)
  4823.         {
  4824.         if (sepcp <= rgfc[i])
  4825.             {
  4826.             error(erroroutput,"sep piece is %d cp is %x, other is %x\n",i,sepcp,rgfc[i]);
  4827.             return(i);
  4828.             }
  4829.         }
  4830.     return(-1);
  4831.     }
  4832.  
  4833. void decode_clx(U32 startpiece,U32 begincp,U32 endcp,FILE *in,FILE *main,FILE *data,U32 fcClx,U32 lcbClx,U32 intervals,U32 chpintervals,U32 *plcfbtePapx,U32 *plcfbteChpx,field_info *all_fields[5],list_info *a_list_info,style * sheet,textportions *portions, ffn *fontnamelist,int headerfooterflag)
  4834.     {
  4835.     int paraendpiece;
  4836.     int paraendpiece2;
  4837.     int seppiece;
  4838.     int index=0;
  4839.     pap *apap=NULL;
  4840.     pap *tappap=NULL;
  4841.     pap *temppap=NULL;
  4842.     chp *achp=NULL;
  4843.     pap fakepap;
  4844.     chp fakechp;
  4845.     sep fakesep;
  4846.     long pos = ftell(in);
  4847.     long mainpos = ftell(main);
  4848.     int i;
  4849.     int k;
  4850.     U32 tapfc1=0;
  4851.     U32 tapfc2=0;
  4852.     
  4853.     U8 clxt;
  4854.     U16 cb;
  4855.     U16 *sprm=NULL;
  4856.     
  4857.     int j=0;
  4858.     int nopieces=0;
  4859.     U32 *rgfc=NULL;
  4860.     U32 *avalrgfc=NULL;
  4861.     int letter;
  4862.     int hack=0;
  4863.     U32 nextfc=0;
  4864.     U32 chpnextfc;
  4865.     U32 clxcount=0;
  4866.     Sprm asprmlist;
  4867.     Sprm *psprmlist=&asprmlist;
  4868.     Sprm *freesprm;
  4869.     U32 lastfc=0;
  4870.     U32 lastchpfc=0;
  4871.     static int metadone=0;
  4872.  
  4873.     signed long nextfootnote=0;
  4874.     signed long nextendnote=0;
  4875.     U32 nextbookmark_b=cp; /*was 0*/
  4876.     U32 nextbookmark_e=cp; /*was 0*/
  4877.  
  4878.     U32 sepxfc;
  4879.     U32 sepcp;
  4880.     sep *asep=NULL;
  4881.     sep *tempsep=NULL;
  4882.  
  4883.     int newpage=1;
  4884.  
  4885.     int notfinished=1;
  4886.     int fccount=0;
  4887.     int paraflag=0;
  4888.     U32 paraendfc=1;
  4889.  
  4890.     int d_count=0;
  4891.  
  4892.     int issection=1;
  4893.  
  4894.     long seek_val=0;
  4895.  
  4896.     fseek(in,fcClx,SEEK_SET);
  4897.     error(erroroutput,"seeking table to (%x) len %d\n",fcClx,lcbClx);
  4898.     error(erroroutput,"begincp is %x\n",begincp);
  4899.     while ((clxcount < lcbClx) && (notfinished))
  4900.         {
  4901.         clxt = getc(in);
  4902.         clxcount++;
  4903.         error(erroroutput,"clxt is %d\n",clxt);
  4904.  
  4905.         psprmlist->list=NULL;
  4906.         psprmlist->next=NULL;
  4907.         psprmlist->len=0;
  4908.  
  4909.         if (clxt == 1)
  4910.             {
  4911.             /*make a list of of these gprrls*/
  4912.             /*decode them when fetched in clxt==2*/
  4913.             /*use bitfields to skip ones i dont care about*/
  4914.             error(erroroutput,"contains  grpprl\n");
  4915.             cb = read_16ubit(in);
  4916.             error(erroroutput,"cb is %d\n",cb);
  4917.             psprmlist->list = (U8 *) malloc(cb);
  4918.             if (psprmlist->list == NULL)
  4919.                 {
  4920.                 fprintf(erroroutput,"mem barfoid\n");
  4921.                 exit(-1);
  4922.                 }
  4923.  
  4924.             clxcount+=(cb+2);
  4925.             psprmlist->len=cb;
  4926.             error(erroroutput,"here come the gpprl\n");
  4927.             for(i=0;i<cb;i++)
  4928.                 {
  4929.                 psprmlist->list[i] = getc(in);
  4930.                 error(erroroutput,"%x",psprmlist->list[i]);
  4931.                 }
  4932.             psprmlist->next = (Sprm *) malloc(sizeof(Sprm));
  4933.             if (psprmlist->next == NULL)
  4934.                 {
  4935.                 fprintf(erroroutput,"mem barfoid\n");
  4936.                 exit(-1);
  4937.                 }
  4938.             psprmlist = psprmlist->next;
  4939.             index++;
  4940.             error(erroroutput,"on gp no %d\n",index);
  4941.             }
  4942.         else if (clxt == 2)
  4943.             {
  4944.             index =0;
  4945.             error(erroroutput,"contains  Plcfpcd\n");
  4946.             
  4947.             nopieces = get_piecetable(in,&rgfc,&avalrgfc,&sprm,&clxcount);
  4948.  
  4949.  
  4950.             /*guess based on first piece whether to go utf 8 or not*/
  4951.             /*
  4952.             actually doing utf8 all the time on complex docs as it
  4953.             turns out not to be such a good test :-(
  4954.             */
  4955.  
  4956.             if ( (header == 0) && (metadone == 0) )
  4957.                 {
  4958.                 fprintf(outputfile,"\n<head>\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=utf-8\">\n</head>\n");
  4959.                 fprintf(outputfile,"<body>\n");
  4960.                 metadone=1;
  4961.                 }
  4962.  
  4963.             for(i=startpiece/*start piece*/;i<nopieces;i++)
  4964.                 {
  4965.  
  4966.                 if ((header == 0) && (metadone ==0))
  4967.                     {
  4968.                     fprintf(outputfile,"<body>\n");
  4969.                     metadone=1;
  4970.                     }
  4971.  
  4972.                 if (notfinished == 0)
  4973.                     break;
  4974.  
  4975.                 /*get the sep*/
  4976.                 if (headerfooterflag == 0)
  4977.                     if (issection)
  4978.                         {
  4979.                         error(erroroutput,"getting sep, %x, piece is %d\n",cp,i);
  4980.                         sepxfc = find_FC_sepx(cp,&sepcp,portions);
  4981.                         tempsep = asep;
  4982.                         asep = get_sep(sepxfc,main);
  4983.                         seppiece = find_piece_cp(sepcp,rgfc,nopieces);
  4984.                         init_chp(&fakechp);
  4985.                         decode_gpprls(&fakepap,&fakechp,asep,sprm,seppiece,&asprmlist,sheet);
  4986.                         if (decode_clx_endnote(rgfc,asep,nopieces,startpiece,begincp,endcp,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,headerfooterflag))
  4987.                             fprintf(outputfile,"\n<br><img src=\"%s/endnoteend.gif\"><br>\n",patterndir());
  4988.                         if ((pagenumber != 1) && (newpage))
  4989.                             sectionbreak(asep);
  4990.  
  4991.                         if (asep != NULL)
  4992.                             {
  4993.                             if (tempsep != NULL)
  4994.                                 free(tempsep);
  4995.                             tempsep=NULL;
  4996.                             }
  4997.                         else
  4998.                             {
  4999.                             asep=tempsep;
  5000.                             tempsep=NULL;
  5001.                             }
  5002.                         issection=0;
  5003.                         }
  5004.  
  5005.                 if (newpage)
  5006.                     {
  5007.                     if (!inatable)
  5008.                         {
  5009.                         newpage =0;
  5010.                         decode_clx_header(rgfc,asep,nopieces,startpiece,begincp,endcp,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,headerfooterflag);
  5011.                         }
  5012.                     else
  5013.                         deferrednewpage=1;
  5014.                     }            
  5015.  
  5016.                 /*push this val back as its something else*/
  5017.                 if (avalrgfc[i] & 0x40000000UL)
  5018.                     {
  5019.                     seek_val = avalrgfc[i] & 0xbfffffffUL;
  5020.                     seek_val = seek_val/2;
  5021.                     error(erroroutput,"tricky ? seek val (%x)\n",seek_val);
  5022.                     error(erroroutput,"seeking main to (the FC %x) for len %d\n",seek_val,rgfc[i+1]-rgfc[i]);
  5023.                     hack=1;
  5024.                     }
  5025.                 else
  5026.                     {
  5027.                     error(erroroutput,"seeking main to (the FC %x) for len %d piece %d\n",seek_val,2*(rgfc[i+1]-rgfc[i]),i);
  5028.                     seek_val = avalrgfc[i];
  5029.                     hack=0;
  5030.                     }
  5031.  
  5032.                 /*sometimes corrupt files have a few offsets in the file that are *past* the end of the file, so ive stuck 
  5033.                 this in, which will sort them out for now*/
  5034.                 if ((mainend < seek_val) || (0 != fseek(main,seek_val,SEEK_SET)))
  5035.                     {
  5036.                     error(erroroutput,"overran the end of the file !!\n");
  5037.                     continue;
  5038.                     }
  5039.  
  5040.                 error(erroroutput,"piece entry fc is %x sprm is %x len is %d\n",seek_val,sprm[i],rgfc[i+1]-rgfc[i]);
  5041.  
  5042.                 error(erroroutput,"1 getting pap HH nopieces is %d, current piece is %d\n",nopieces,i);
  5043.                 temppap = apap;
  5044.                 apap = NULL;
  5045.                 error(erroroutput,"fccount is %x, paraendfc is %x\n",fccount,paraendfc);
  5046.                 if (fccount == paraendfc-1)
  5047.                     paraflag=1;
  5048.                 apap = get_complex_pap(seek_val,plcfbtePapx,i,nopieces,intervals,rgfc,main,avalrgfc,&nextfc,¶endfc,¶endpiece,sheet,a_list_info);
  5049.                 fflush(main);
  5050.                 error(erroroutput," the next para is at (%x)\n",nextfc);
  5051.                 if (apap == NULL)
  5052.                     {
  5053.                     error(erroroutput,"we failed in out attempt to get a paragraph\n");
  5054.                     if (temppap == NULL)
  5055.                         {
  5056.                         apap = (pap *) malloc(sizeof(pap));
  5057.                         if (apap == NULL)
  5058.                             {
  5059.                             fprintf(erroroutput,"no mem aieee\n");
  5060.                             exit(-1);
  5061.                             }
  5062.                         init_pap(apap);
  5063.                         }
  5064.                     else
  5065.                         {
  5066.                         error(erroroutput,"using previous pap\n");
  5067.                         apap = temppap;
  5068.                         temppap = NULL;
  5069.                         }
  5070.                     }
  5071.                 else
  5072.                     {
  5073.                     if (paraflag)
  5074.                         {
  5075.                         end_para(temppap,apap);
  5076.                         paraflag=0;
  5077.                         }
  5078.                     if (temppap != NULL)
  5079.                         free(temppap);
  5080.                     temppap = NULL;
  5081.                     }
  5082.  
  5083.                 /*begin tappap search*/
  5084.                 /*if we're in a table search for the one with fTtp*/
  5085.             
  5086.                 decode_gpprls(apap,&fakechp,&fakesep,sprm,paraendpiece,&asprmlist,sheet);
  5087.  
  5088.                 if (apap->fInTable)
  5089.                     {
  5090.                     k = i;
  5091.                     do
  5092.                         {
  5093.                         tapfc1 = avalrgfc[k];
  5094.                         error(erroroutput,"1. we search for the tap here\n");
  5095.                         error(erroroutput,"tappap nexts are %x, k is %x\n",tapfc1,k);
  5096.                         do
  5097.                             {
  5098.                             if (tappap != NULL)
  5099.                                 {
  5100.                                 free(tappap);
  5101.                                 tappap=NULL;
  5102.                                 }
  5103.                             tapfc2 = tapfc1;
  5104.                             tappap = get_complex_pap(tapfc1,plcfbtePapx,k,nopieces,intervals,rgfc,main,avalrgfc,&tapfc1,NULL,¶endpiece2,sheet,a_list_info);
  5105.                             if (tappap != NULL)
  5106.                                 decode_gpprls(tappap,&fakechp,&fakesep,sprm,paraendpiece2,&asprmlist,sheet);
  5107.                             }
  5108.                         while( (tappap != NULL) && (!tappap->fTtp)  && (tapfc1 != tapfc2)) ;
  5109.                         k++;
  5110.                         }
  5111.                     while ( (tappap != NULL) && (!tappap->fTtp)  && (k<nopieces) );
  5112.                     /*
  5113.                     at this stage tappap has the correct row structure stored in it
  5114.                     that we want apap to have
  5115.                     */
  5116.                     if (tappap != NULL)
  5117.                         {
  5118.                         copy_tap(&(apap->ourtap),&(tappap->ourtap));
  5119.                         error(erroroutput,"finished search for the tap here\n");
  5120.                         error(erroroutput,"no of cells is %d, %d\n",apap->ourtap.cell_no,tappap->ourtap.cell_no);
  5121.                         free(tappap);
  5122.                         tappap=NULL;
  5123.                         }
  5124.                     }
  5125.                 /*end tappap search*/
  5126.                 
  5127.                 error(erroroutput,"AT THIS POINT %d\n",apap->istd);
  5128.         
  5129.                 if (achp != NULL)
  5130.                     free(achp);
  5131.                 achp = get_complex_chp(seek_val,plcfbteChpx,i,nopieces,chpintervals,rgfc,main,avalrgfc,&chpnextfc,sheet,apap->istd);
  5132.                 error(erroroutput," CHP: the next para is at (%x)\n",chpnextfc);
  5133.                 if (achp == NULL)
  5134.                     {
  5135.                     error(erroroutput,"we failed in out attempt to get a chp\n");
  5136.                     achp = (chp *) malloc(sizeof(chp));
  5137.                     if (achp == NULL)
  5138.                         {
  5139.                         fprintf(erroroutput,"no mem aieee\n");
  5140.                         exit(-1);
  5141.                         }
  5142.                     init_chp(achp);
  5143.  
  5144.                     }
  5145.  
  5146.                 if (achp->color[0] == '\0')
  5147.                     {
  5148.                     if (headerfooterflag == 1)
  5149.                         strcpy(achp->color,"#7f5555");
  5150.                     else if (headerfooterflag == 2)
  5151.                         strcpy(achp->color,"#330099");
  5152.                     else if (headerfooterflag == 3)
  5153.                         strcpy(achp->color,"#ff7777");
  5154.                     }
  5155.  
  5156.                 /*
  5157.                 the gpprl that id added is the one that belongs to the 
  5158.                 piece that has the paragraph mark
  5159.                 */
  5160.                 
  5161.                 error(erroroutput,"decoding gpprl with (%x) index %d\n",sprm[paraendpiece],paraendpiece);
  5162.                 fakepap.istd = apap->istd;
  5163.                 decode_gpprls(&fakepap,achp,&fakesep,sprm,paraendpiece,&asprmlist,sheet);
  5164.                 error(erroroutput,"1) ilfo is %d\n",apap->ilfo);
  5165.                 decode_e_list(apap,achp,a_list_info);
  5166.                 decode_e_chp(achp);
  5167.                 decode_e_specials(apap,achp,a_list_info);
  5168.                 decode_e_table(apap,achp,a_list_info);
  5169.                 decode_s_table(apap,achp,a_list_info);
  5170.                 decode_s_specials(apap,achp,a_list_info);
  5171.                 decode_s_chp(achp,fontnamelist);
  5172.  
  5173.                 error(erroroutput,"2) ilfo is %d\n",apap->ilfo);
  5174.                 j=0;
  5175.  
  5176.                 /*this are the count of elements (can be both 8 and 16 bit)*/
  5177.                 fccount=seek_val-1;
  5178.                 error(erroroutput,"fcount is %x pos is %x\n",fccount,ftell(main));
  5179.                 /*this is the actual file position, always in bytes*/
  5180.                 while(j<rgfc[i+1]-rgfc[i])
  5181.                     {
  5182.                     /*get the sep*/
  5183.                     if (headerfooterflag == 0)
  5184.                         if (issection)
  5185.                             {
  5186.                             error(erroroutput,"getting sep, %x, piece is %d\n",cp,i);
  5187.                             sepxfc = find_FC_sepx(cp,&sepcp,portions);
  5188.                             tempsep=NULL;
  5189.                             asep = get_sep(sepxfc,main);
  5190.                             seppiece = find_piece_cp(sepcp,rgfc,nopieces);
  5191.                             decode_gpprls(&fakepap,&fakechp,asep,sprm,seppiece,&asprmlist,sheet);
  5192.                             if (decode_clx_endnote(rgfc,asep,nopieces,startpiece,begincp,endcp,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,headerfooterflag))
  5193.                                 fprintf(outputfile,"\n<br><img src=\"%s/endnoteend.gif\"><br>\n",patterndir());
  5194.                             if ((pagenumber != 1) && (newpage))
  5195.                                 sectionbreak(asep);
  5196.                             issection=0;
  5197.  
  5198.                             if (asep != NULL)
  5199.                                 {
  5200.                                 if (tempsep != NULL)
  5201.                                     free(tempsep);
  5202.                                 tempsep=NULL;
  5203.                                 }
  5204.                             else
  5205.                                 {
  5206.                                 asep=tempsep;
  5207.                                 tempsep=NULL;
  5208.                                 }
  5209.                             }
  5210.                     
  5211.                     if (newpage)
  5212.                         {
  5213.                         if (header == 0)
  5214.                             {
  5215.                             if (!inatable)
  5216.                                 {
  5217.                                 newpage =0;
  5218.                                 decode_clx_header(rgfc,asep,nopieces,startpiece,begincp,endcp,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,headerfooterflag);
  5219.                                 }
  5220.                             else
  5221.                                 deferrednewpage=1;
  5222.                             }
  5223.                         }            
  5224.  
  5225.                     if (!hack)
  5226.                         {
  5227.                         letter = read_16ubit(main);
  5228.                         fccount+=2;    
  5229.                         }
  5230.                     else
  5231.                         {
  5232.                         letter = getc(main);
  5233.                         fccount++;
  5234.                         }
  5235.  
  5236.                     if (j==0) 
  5237.                         {
  5238.                         if ( (letter != 12) && (letter!=13) )
  5239.                             {
  5240.                             decode_s_list(apap,achp,a_list_info,fontnamelist,DONTIGNORENUM);
  5241.                             error(erroroutput,"finished list hwew letter was %d %x\n",letter,letter);
  5242.                             }
  5243.                         else
  5244.                             {
  5245.                             error(erroroutput,"finished list hwew letter was %d %x\n",letter,letter);
  5246.                             }
  5247.                         }
  5248.  
  5249.  
  5250.                     if (fccount >= nextfc)
  5251.                         {
  5252.                         lastfc = nextfc;
  5253.                         error(erroroutput,"the fc is (%x) and the first fc after end of para is (%x)",fccount,nextfc);
  5254.                         error(erroroutput,"so im looking for the pap again\n");
  5255.                         error(erroroutput,"2 getting pap HH, jc was %d\n",apap->justify);
  5256.                         if (apap != NULL)
  5257.                             {
  5258.                             temppap = apap;
  5259.                             apap = NULL;
  5260.                             }
  5261.                         if (fccount == paraendfc-1)
  5262.                             paraflag=1;
  5263.                         apap = get_complex_pap(fccount,plcfbtePapx,i,nopieces,intervals,rgfc,main,avalrgfc,&nextfc,¶endfc,¶endpiece,sheet,a_list_info);
  5264.                         fflush(main);
  5265.                         error(erroroutput,"the nextfc for pap one is at %x\n",nextfc);
  5266.  
  5267.                         if (apap == NULL)
  5268.                             {
  5269.                             error(erroroutput,"we failed in out attempt to get a paragraph\n");
  5270.                             if (temppap == NULL)
  5271.                                 {
  5272.                                 apap = (pap *) malloc(sizeof(pap));
  5273.                                 if (apap == NULL)
  5274.                                     {
  5275.                                     fprintf(erroroutput,"no mem aieee\n");
  5276.                                     exit(-1);
  5277.                                     }
  5278.                                 init_pap(apap);
  5279.                                 }
  5280.                             else
  5281.                                 {
  5282.                                 apap = temppap;
  5283.                                 temppap = NULL;
  5284.                                 error(erroroutput,"using previous pap, jc is now %d\n",apap->justify);
  5285.                                 }
  5286.                             }
  5287.                         else
  5288.                             {
  5289.                             /*begin tappap search*/
  5290.                             /*if we're in a table search for the one with fTtp*/
  5291.                             decode_gpprls(apap,&fakechp,&fakesep,sprm,paraendpiece,&asprmlist,sheet);
  5292.                             if (apap->fInTable)
  5293.                                 {
  5294.                                 k = i;
  5295.                                 do
  5296.                                     {
  5297.                                     if (k==i)
  5298.                                         tapfc1 = fccount;
  5299.                                     else
  5300.                                         tapfc1 = avalrgfc[k];
  5301.                                     error(erroroutput,"2. we search for the tap here\n");
  5302.                                     error(erroroutput,"tappap nexts are %x, k is %x\n",tapfc1,k);
  5303.                                     do
  5304.                                         {
  5305.                                         if (tappap != NULL)
  5306.                                             {
  5307.                                             free(tappap);
  5308.                                             tappap=NULL;
  5309.                                             }
  5310.                                         tapfc2 = tapfc1;
  5311.                                         tappap = get_complex_pap(tapfc1,plcfbtePapx,k,nopieces,intervals,rgfc,main,avalrgfc,&tapfc1,NULL,¶endpiece2,sheet,a_list_info);
  5312.                                         if (tappap != NULL)
  5313.                                             decode_gpprls(tappap,&fakechp,&fakesep,sprm,paraendpiece2,&asprmlist,sheet);
  5314.                                         }
  5315.                                     while( (tappap != NULL) && (!tappap->fTtp) && (tapfc1 != tapfc2)) ;
  5316.                                     k++;
  5317.                                     }
  5318.                                 while ( (tappap != NULL) && (!tappap->fTtp) && (k<nopieces) );
  5319.                                 /*
  5320.                                 at this stage tappap has the correct row structure stored in it
  5321.                                 that we want apap to have
  5322.                                 */
  5323.                                 if (tappap != NULL)
  5324.                                     {
  5325.                                     copy_tap(&(apap->ourtap),&(tappap->ourtap));
  5326.                                     error(erroroutput,"finished 2nd search for the tap here\n");
  5327.                                     error(erroroutput,"no of cells is %d, %d\n",apap->ourtap.cell_no,tappap->ourtap.cell_no);
  5328.                                     free(tappap);
  5329.                                     tappap=NULL;
  5330.                                     }
  5331.                                 }
  5332.                             /*end tappap search*/
  5333.  
  5334.                             /*last gasp of the pap*/
  5335.                             if (paraflag)
  5336.                                 {
  5337.                                 end_para(temppap,apap);
  5338.                                 paraflag=0;
  5339.                                 }
  5340.                             
  5341.                             /*remove unneeded pap*/
  5342.                             if (temppap != NULL)
  5343.                                 free(temppap);
  5344.                                 
  5345.                             temppap = NULL;
  5346.                             }
  5347.  
  5348.                         }
  5349.  
  5350.  
  5351.                     if ((fccount >= chpnextfc)  || (fccount >= lastfc))
  5352.                         {
  5353.                         lastchpfc=1;
  5354.                         if (achp != NULL)
  5355.                             {
  5356.                             free(achp);
  5357.                             achp=NULL;
  5358.                             }
  5359.                         achp = get_complex_chp(fccount,plcfbteChpx,i,nopieces,chpintervals,rgfc,main,avalrgfc,&chpnextfc,sheet,apap->istd);
  5360.                         error(erroroutput," CHP: the next para is at (%x)\n",chpnextfc);
  5361.  
  5362.                         if (achp == NULL)
  5363.                             error(erroroutput,"we failed in out attempt to get a chp\n");
  5364.                         else
  5365.                             {
  5366.                             if (achp->color[0] == '\0')
  5367.                                 {
  5368.                                 if (headerfooterflag == 1)
  5369.                                     strcpy(achp->color,"#7f5555");
  5370.                                 else if (headerfooterflag == 2)
  5371.                                     strcpy(achp->color,"#330099");
  5372.                                 else if (headerfooterflag == 3)
  5373.                                     strcpy(achp->color,"#ff7777");
  5374.                                 }
  5375.         
  5376.                             error(erroroutput,"before gprl chp fontcode is %d\n",achp->fontcode);
  5377.                             decode_gpprls(&fakepap,achp,&fakesep,sprm,paraendpiece,&asprmlist,sheet);
  5378.                             error(erroroutput,"after gprl chp fontcode is %d\n",achp->fontcode);
  5379.                             decode_e_list(apap,achp,a_list_info);
  5380.                             decode_e_chp(achp);
  5381.                             error(erroroutput,"after decode chp fontcode is %d\n",achp->fontcode);
  5382.                             }
  5383.                         }
  5384.  
  5385.                     if (fccount >= lastfc) 
  5386.                         {
  5387.                         decode_e_specials(apap,achp,a_list_info);
  5388.                         decode_e_table(apap,achp,a_list_info);
  5389.                         decode_s_table(apap,achp,a_list_info);
  5390.                         decode_s_specials(apap,achp,a_list_info);
  5391.                         decode_s_chp(achp,fontnamelist);
  5392.                         lastfc=-1;
  5393.                         }
  5394.  
  5395.                     if (lastchpfc) 
  5396.                         {
  5397.                         lastchpfc=-1;
  5398.                         decode_s_chp(achp,fontnamelist);
  5399.                         if ( ((letter != 12) && (letter != 13)) )
  5400.                             {
  5401.                             decode_s_list(apap,achp,a_list_info,fontnamelist,DONTIGNORENUM);
  5402.                             error(erroroutput,"list started following letter is %d\n",letter);
  5403.                             }
  5404.                         else 
  5405.                             error(erroroutput,"list started following letter is %d\n",letter);
  5406.                         }
  5407.  
  5408.  
  5409.                     if (cp >= begincp)
  5410.                         {
  5411.                         if ((headerfooterflag >0) && (headerfooterflag < 2))
  5412.                             {
  5413.                             if (letter == 13)
  5414.                                 {
  5415.                                 /*
  5416.                                 headers and footers seem to continue until 2 0x0d are reached, they dont
  5417.                                 appear after all to go until the len derived from the header table
  5418.                                 like i thought originally.
  5419.                                 */
  5420.                                 d_count++;
  5421.                                 if (d_count == 2)
  5422.                                     {
  5423.                                     notfinished=0;
  5424.                                     break;
  5425.                                     }
  5426.                                 }
  5427.                             else
  5428.                                 d_count=0;
  5429.                             }
  5430.                         
  5431.                         error(erroroutput,"decoding letter: %c, fc is %x, nextfc is %x\n",letter,fccount,nextfc);
  5432.  
  5433.                         if ( (realcp == nextfootnote) && (headerfooterflag == 0) ) 
  5434.                             {
  5435.                             decode_f_reference(portions);
  5436.                             get_next_f_ref(portions,&nextfootnote);
  5437.                             }
  5438.                         
  5439.                         if ( (realcp == nextendnote) && (headerfooterflag == 0) ) 
  5440.                             {
  5441.                             decode_e_reference(portions);
  5442.                             get_next_e_ref(portions,&nextendnote);
  5443.                             }
  5444.  
  5445.                         while (realcp == nextbookmark_b) 
  5446.                             nextbookmark_b = decode_b_bookmark(&(portions->l_bookmarks),&(portions->bookmarks));
  5447.  
  5448.                         while (realcp == nextbookmark_e) 
  5449.                             nextbookmark_e = decode_e_bookmark(&(portions->l_bookmarks));
  5450.  
  5451.                         if (hack)
  5452.                             newpage = decode_letter(letter,1,apap,achp,all_fields[0],main,data,fontnamelist,a_list_info,portions,&issection);
  5453.                         else
  5454.                             newpage = decode_letter(letter,1,apap,achp,all_fields[0],main,data,fontnamelist,a_list_info,portions,&issection);
  5455.  
  5456.                         error(erroroutput,"W:sync, actuallt at %x, fccount is %x and aval is %xthough\n",ftell(main),fccount,fccount);
  5457.                         }
  5458.                     else
  5459.                         {
  5460.                         realcp++;
  5461.                         cp++;
  5462.                         }
  5463.  
  5464.  
  5465.                     /*if newpage then decode header*/
  5466.                     if (newpage)
  5467.                         {
  5468.  
  5469.                         if ((inatable)  && newpage == 2)
  5470.                             {
  5471.                             /*in this case we have ended a row, so we should take the opportunity to halt the table*/
  5472.                             fprintf(outputfile,"\n</table>\n");
  5473.                             inatable=0;
  5474.                             newpage=1;
  5475.                             }
  5476.                         
  5477.                         error(erroroutput,"clx footer\n");
  5478.  
  5479.                         if ((!inatable) && (newpage == 1))
  5480.                             {
  5481.                             decode_clx_footer(rgfc,asep,nopieces,startpiece,begincp,endcp,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,headerfooterflag);
  5482.                             if (!issection)
  5483.                                 pagebreak();
  5484.                             }    
  5485.                         else if (newpage == 1)
  5486.                             deferrednewpage=1;
  5487.                         }
  5488.  
  5489.             
  5490.  
  5491.  
  5492.                     /*get the sep*/
  5493.                     if (headerfooterflag == 0)
  5494.                         if (issection)
  5495.                             {
  5496.                             error(erroroutput,"getting sep, %x\n",cp);
  5497.                             sepxfc = find_FC_sepx(cp,&sepcp,portions);
  5498.                             asep = get_sep(sepxfc,main);
  5499.                             seppiece = find_piece_cp(sepcp,rgfc,nopieces);
  5500.                             decode_gpprls(&fakepap,&fakechp,asep,sprm,seppiece,&asprmlist,sheet);
  5501.                             if (decode_clx_endnote(rgfc,asep,nopieces,startpiece,begincp,endcp,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,headerfooterflag))
  5502.                                 fprintf(outputfile,"\n<br><img src=\"%s/endnoteend.gif\"><br>\n",patterndir());
  5503.                             if ((pagenumber != 1) && (newpage))
  5504.                                 sectionbreak(asep);
  5505.                             issection=0;
  5506.  
  5507.                             if (asep!= NULL)
  5508.                                 {
  5509.                                 if (tempsep != NULL)
  5510.                                     free(tempsep);
  5511.                                 tempsep=NULL;
  5512.                                 }
  5513.                             else
  5514.                                 {
  5515.                                 asep=tempsep;
  5516.                                 tempsep=NULL;
  5517.                                 }
  5518.                             }
  5519.  
  5520.                     if (cp >= endcp)
  5521.                         {
  5522.                         error(erroroutput,"reached end of header or main, headerfootflag is %d\n",headerfooterflag);
  5523.                             notfinished=0;
  5524.                             error(erroroutput,"end of header or main break\n");
  5525.                             break;
  5526.                         }
  5527.  
  5528.                     j++;
  5529.                     }/*end for/while j*/
  5530.                     
  5531.                 error(erroroutput,"here after header ?\n");
  5532.  
  5533.                 if (achp != NULL)
  5534.                     {
  5535.                     free(achp);
  5536.                     achp = NULL;
  5537.                     }
  5538.                 }
  5539.             }
  5540.         else
  5541.             fprintf(erroroutput,"some kind of error occured, byte count off\n");
  5542.         }
  5543.  
  5544.  
  5545.     if (apap == NULL)
  5546.         {
  5547.         apap = (pap *)malloc(sizeof(pap));
  5548.         if (apap == NULL)
  5549.             return;
  5550.         }
  5551. #if 0    
  5552.     apap->istd = 0;
  5553.     apap->ilvl=-1;
  5554.     apap->tableflag=0;
  5555. #endif
  5556.     init_pap(apap);
  5557.     decode_e_list(apap,achp,a_list_info);
  5558.     decode_e_specials(apap,achp,a_list_info);
  5559.     decode_e_table(apap,achp,a_list_info);
  5560.     if (apap !=NULL)
  5561.         free(apap);
  5562.     if (achp !=NULL)
  5563.         free(achp);
  5564.  
  5565.     if (!newpage)
  5566.         {
  5567.         error(erroroutput,"clx footer 2\n");
  5568.         decode_clx_footer(rgfc,asep,nopieces,startpiece,begincp,endcp,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,headerfooterflag);
  5569.         if (decode_clx_endnote(rgfc,asep,nopieces,startpiece,begincp,endcp,in,main,data,fcClx,lcbClx,intervals,chpintervals,plcfbtePapx,plcfbteChpx,all_fields,a_list_info,sheet,portions,fontnamelist,headerfooterflag))
  5570.             fprintf(outputfile,"\n<br><img src=\"%s/endnoteend.gif\"><br>\n",patterndir());
  5571.         }
  5572.  
  5573.     if (rgfc != NULL)
  5574.         free(rgfc);
  5575.     if (avalrgfc != NULL)
  5576.         free(avalrgfc);
  5577.     if (sprm != NULL)
  5578.         free(sprm);
  5579.  
  5580.     if (asep != NULL)
  5581.         free(asep);
  5582.  
  5583.     psprmlist = &asprmlist;
  5584.     if (psprmlist->list != NULL)
  5585.             free(psprmlist->list);
  5586.     psprmlist = psprmlist->next;
  5587.     while (psprmlist != NULL)
  5588.         {
  5589.         freesprm = psprmlist;
  5590.         psprmlist = psprmlist->next;
  5591.         if (freesprm->list != NULL)
  5592.             free(freesprm->list);
  5593.         free(freesprm);
  5594.         }
  5595.  
  5596.     fseek(in,pos,SEEK_SET);
  5597.     fseek(main,mainpos,SEEK_SET);
  5598.     }
  5599.  
  5600.  
  5601.  
  5602.         
  5603. int decode_ilfo(pap *retpap,list_info *a_list_info)
  5604.     {
  5605.     int j;
  5606.     
  5607.     /*
  5608.     else now we use our a_list_data to generate the paps list_data
  5609.     including the text to use, whether to prepend a index or not
  5610.     what format the index is in, and the start index
  5611.     */
  5612.     /*
  5613.     first get the text, ) / . / string / whatever
  5614.     */
  5615.     error(erroroutput,"ilfo %d of %d\n",retpap->ilfo,a_list_info->nooflfos);
  5616.     if (retpap->ilfo >= a_list_info->nooflfos)
  5617.         {
  5618.         if (retpap->ilfo != 2047)
  5619.             {
  5620.             error(erroroutput,"hmm problem\n");
  5621.             return(-1);
  5622.             }
  5623.         else
  5624.             error(erroroutput,"legacy anld\n");
  5625.         return(-1);
  5626.         }
  5627.  
  5628.     /*
  5629.     what should happen here, is after we get this base list data, 
  5630.     we add the overrides to a copy of our own
  5631.     */
  5632.  
  5633.     retpap->list_data = &(a_list_info->o_list_def[retpap->ilfo]);
  5634.     
  5635.     retpap->list_data->id = a_list_info->lst_ids[retpap->ilfo];
  5636.     for (j=0;j<retpap->list_data->len;j++)
  5637.                 error(erroroutput,"--> %c",retpap->list_data->list_string[j]);
  5638.  
  5639.  
  5640.     error(erroroutput,"ilfo request is %d, the id in the lfo is %x",retpap->ilfo,a_list_info->lst_ids[retpap->ilfo]);
  5641.     j=0;
  5642.     while(j<a_list_info->nooflsts)
  5643.         {
  5644.         if (a_list_info->o_lst_ids[j] == retpap->list_data->id)
  5645.             {
  5646.             error(erroroutput,"and the returned index is %d\n",j);
  5647.             return(j);
  5648.             }
  5649.         j++;
  5650.         }
  5651.  
  5652.     return(0);
  5653.     }
  5654.  
  5655.  
  5656.  
  5657.  
  5658.  
  5659. void decode_s_table(pap *apap,chp *achp,list_info *a_list_info)
  5660.     {
  5661.     int redotable=0,i;
  5662.     float width;
  5663.     int clearedspecials=0;
  5664.     chp reset;
  5665.     pap resetpap;
  5666.     int resetchp=0;
  5667.  
  5668.     int tablewidth;
  5669.  
  5670.     init_chp(&reset);
  5671.     init_pap(&resetpap);
  5672.     reset.fontcode=-2;
  5673.     reset.ascii_font=currentfontcode+1;
  5674.  
  5675.     error(erroroutput,"decoding start specials istd is %d\n",apap->istd);
  5676.  
  5677.     if ((!(inatable)) && (apap->fInTable))
  5678.         {
  5679.         if (!resetchp)
  5680.             {
  5681.             decode_e_chp(&reset);
  5682.             resetchp=1;
  5683.             }
  5684.         if (!clearedspecials)
  5685.             {
  5686.             decode_e_specials(&resetpap,NULL,NULL);
  5687.             clearedspecials=1;
  5688.             }
  5689.         flushbreaks(0);
  5690.         do_indent(apap);
  5691.     
  5692.         if (notablewidth)    
  5693.             fprintf(outputfile,"\n<table border=1>");
  5694.         else    
  5695.             fprintf(outputfile,"\n<table border=1 width=\"");
  5696.         /*search for tap*/
  5697.         rowcount=0;
  5698.         inatable=1;
  5699.         inarow=0;
  5700.         inacell=0;
  5701.         lastrowlen=apap->ourtap.cell_no;
  5702.         error(erroroutput,"lastrowlen is %d\n",lastrowlen);
  5703.         tablewidth=0;
  5704.         for (i=0;i<apap->ourtap.cell_no+1;i++)
  5705.             {
  5706.             lastcellwidth[i] = apap->ourtap.cellwidth[i];
  5707.             error(erroroutput,"dx-->%d",lastcellwidth[i]);
  5708.             tablewidth+=lastcellwidth[i];
  5709.             }
  5710.         tablewidth-=lastcellwidth[0];
  5711.         error(erroroutput,"set table, tablewidth is twirps is %d\n",tablewidth);
  5712.         if (!notablewidth)
  5713.             fprintf(outputfile,"%d\">\n",tablewidth/TWIRPS_PER_H_PIXEL);
  5714.         }
  5715.  
  5716.     if ( ((inatable) && (apap->fInTable) && (!apap->fTtp)) || ((inatable) && (!inacell) && (inarow)) )
  5717.         {
  5718.         if (inarow == 0)
  5719.             {
  5720.             if (lastrowlen != apap->ourtap.cell_no)
  5721.                 {
  5722.                 error(erroroutput,"well have to start a new table\n");
  5723.                 redotable=1;
  5724.                 }
  5725.             else 
  5726.                 {
  5727.                 for (i=0;i<apap->ourtap.cell_no+1;i++)
  5728.                     {
  5729.                     if (lastcellwidth[i] != apap->ourtap.cellwidth[i])
  5730.                         redotable=1;
  5731.                     }
  5732.                 }
  5733.  
  5734.             if (redotable)
  5735.                 {
  5736.                 if (!clearedspecials)
  5737.                     {
  5738.                     /*decode_e_specials(&reset,achp,a_list_info);*/
  5739.                     clearedspecials=1;
  5740.                     }
  5741.                 if (!resetchp)
  5742.                     {
  5743.                     decode_e_chp(&reset);
  5744.                     resetchp=1;
  5745.                     }
  5746.                 fprintf(outputfile,"\n</table>\n");
  5747. #if 0
  5748.                 flushbreaks(0);
  5749. #endif
  5750.                 if (notablewidth)
  5751.                     fprintf(outputfile,"\n<table border=1>\n");
  5752.                 else
  5753.                     fprintf(outputfile,"\n<table border=1 width=\"100%%\">\n");
  5754.                 error(erroroutput,"redone table\n");
  5755.                 /*no need to reset rowcount*/
  5756.                 inatable=1;
  5757.                 inarow=1;
  5758.                 inacell=0;
  5759.                 lastrowlen=apap->ourtap.cell_no;
  5760.                 for (i=0;i<apap->ourtap.cell_no+1;i++)
  5761.                     lastcellwidth[i] = apap->ourtap.cellwidth[i];
  5762.  
  5763.                 }
  5764.  
  5765.             if (!clearedspecials)
  5766.                 {
  5767.                 /*decode_e_specials(&reset,achp,a_list_info);*/
  5768.                 clearedspecials=1;
  5769.                 }
  5770.             if (!resetchp)
  5771.                 {
  5772.                 decode_e_chp(&reset);
  5773.                 resetchp=1;
  5774.                 }
  5775.             fprintf(outputfile,"\n<tr>\n");
  5776.             rowcount++;
  5777.             colcount=0;
  5778.             inarow = 1;
  5779.             }
  5780.             
  5781.         if ( (inacell == 0) && (colcount < apap->ourtap.cell_no) )
  5782.             {
  5783.             width = (apap->ourtap.cellwidth[colcount+1]-apap->ourtap.cellwidth[colcount])*100;
  5784.             width = rint(width/apap->ourtap.tablewidth);
  5785.             if (notablewidth)
  5786.                 fprintf(outputfile,"\n<td valign=\"top\" "); 
  5787.             else
  5788.                 fprintf(outputfile,"\n<td valign=\"top\" width=\"%.0f%%\" ",width); 
  5789.             if (apap->ourtap.rowheight != 0)
  5790.                 fprintf(outputfile,"height=\"%d\"",abs(apap->ourtap.rowheight)/TWIRPS_PER_V_PIXEL); 
  5791.             chpson();
  5792.  
  5793.             output_tablebg(apap);
  5794.  
  5795.             cellempty=1;
  5796.             inacell=1;
  5797.             colcount++;
  5798.             }
  5799.         else if ( (inacell == 0) && (apap->ourtap.cell_no == 0) )
  5800.             {
  5801.             error(erroroutput,"dont have information as to width of cells\n");
  5802. #if 0
  5803.             if (!resetchp)
  5804.                 {
  5805.                 decode_e_chp(&reset);
  5806.                 resetchp=1;
  5807.                 }
  5808. #endif
  5809.             fprintf(outputfile,"\n<td valign=\"top\" ");
  5810.             if (apap->ourtap.rowheight != 0)
  5811.                 fprintf(outputfile,"height=\"%d\"",abs(apap->ourtap.rowheight)/TWIRPS_PER_V_PIXEL); 
  5812.             chpson();
  5813.  
  5814.             output_tablebg(apap);
  5815.  
  5816.             cellempty=1;
  5817.             inacell=1;
  5818.             colcount++;
  5819.             }
  5820.  
  5821.         check_auto_color(achp);
  5822.             
  5823.         /*weve come into another cell*/
  5824.         }
  5825.     }
  5826.  
  5827. void decode_s_specials(pap *apap,chp *achp,list_info *a_list_info)
  5828.     {
  5829.     
  5830.     int resetchp=0;
  5831.     
  5832.     chp reset;
  5833.  
  5834.     init_chp(&reset);
  5835.     reset.fontcode=-2;
  5836.  
  5837.     error(erroroutput,"decoding start specials istd is %d\n",apap->istd);
  5838.  
  5839.     do_indent(apap);
  5840.  
  5841.     if ((apap->justify == 1) && (incenter == 0))
  5842.         {
  5843.         incenter =1;
  5844.         fprintf(outputfile,"\n<CENTER>");
  5845.         error(erroroutput,"begin of center\n");
  5846.         }
  5847.  
  5848.     if ((apap->justify == 2) && (inrightjust == 0))
  5849.         {
  5850.         inrightjust =1;
  5851.         fprintf(outputfile,"\n<DIV align=right>");
  5852.         error(erroroutput,"begin of right\n");
  5853.         }
  5854.  
  5855.     if (ignoreheadings == 0)
  5856.         {
  5857.         if ((apap->istd == 1) && (inah1 != 1))
  5858.             {
  5859.             inah1=1;
  5860.             if (!resetchp)
  5861.                 {
  5862.                 decode_e_chp(&reset);
  5863.                 resetchp=1;
  5864.                 }
  5865.             fprintf(outputfile,"<H1>");
  5866.             }
  5867.  
  5868.         if ((apap->istd == 2) && (inah1 != 2))
  5869.             {
  5870.             inah1=2;
  5871.             if (!resetchp)
  5872.                 {
  5873.                 decode_e_chp(&reset);
  5874.                 resetchp=1;
  5875.                 }
  5876.             fprintf(outputfile,"<H2>");
  5877.             }
  5878.  
  5879.         if ((apap->istd == 3) && (inah1 != 3))
  5880.             {
  5881.             inah1=3;
  5882.             if (!resetchp)
  5883.                 {
  5884.                 decode_e_chp(&reset);
  5885.                 resetchp=1;
  5886.                 }
  5887.             fprintf(outputfile,"<H3>");
  5888.             }
  5889.  
  5890.         if ((apap->istd == 4) && (inah1 != 4))
  5891.             {
  5892.             inah1=4;
  5893.             if (!resetchp)
  5894.                 {
  5895.                 decode_e_chp(&reset);
  5896.                 resetchp=1;
  5897.                 }
  5898.             fprintf(outputfile,"<H4>");
  5899.             }
  5900.  
  5901.         if ((apap->istd == 5) && (inah1 != 5))
  5902.             {
  5903.             inah1=5;
  5904.             if (!resetchp)
  5905.                 {
  5906.                 decode_e_chp(&reset);
  5907.                 resetchp=1;
  5908.                 }
  5909.             fprintf(outputfile,"<H5>");
  5910.             }
  5911.  
  5912.         if ((apap->istd == 6) && (inah1 != 6))
  5913.             {
  5914.             inah1=6;
  5915.             if (!resetchp)
  5916.                 {
  5917.                 decode_e_chp(&reset);
  5918.                 resetchp=1;
  5919.                 }
  5920.             fprintf(outputfile,"<H6>");
  5921.             }
  5922.  
  5923.         if ((apap->istd == 7) && (inah1 != 7))
  5924.             {
  5925.             inah1=7;
  5926.             if (!resetchp)
  5927.                 {
  5928.                 decode_e_chp(&reset);
  5929.                 resetchp=1;
  5930.                 }
  5931.             fprintf(outputfile,"<H7>");
  5932.             }
  5933.  
  5934.         if ((apap->istd == 8) && (inah1 != 8))
  5935.             {
  5936.             inah1=8;
  5937.             if (!resetchp)
  5938.                 {
  5939.                 decode_e_chp(&reset);
  5940.                 resetchp=1;
  5941.                 }
  5942.             fprintf(outputfile,"<H8>");
  5943.             }
  5944.  
  5945.         if ((apap->istd == 9) && (inah1 != 9))
  5946.             {
  5947.             inah1=9;
  5948.             if (!resetchp)
  5949.                 {
  5950.                 decode_e_chp(&reset);
  5951.                 resetchp=1;
  5952.                 }
  5953.             fprintf(outputfile,"<H9>");
  5954.             }
  5955.         }    
  5956.  
  5957.     error(erroroutput,"manually doing start chp\n");
  5958.     }
  5959.  
  5960. int decode_e_table(pap *apap,chp *achp,list_info *a_list_info)
  5961.     {
  5962.     int ret=0;
  5963.     pap reset;
  5964.     chp resetc;
  5965.     int clearedspecials=0;
  5966.     error(erroroutput,"decoding end table\n");
  5967.  
  5968.     init_pap(&reset);
  5969.     init_chp(&resetc);
  5970.     resetc.fontcode=-2;
  5971.     resetc.ascii_font=currentfontcode+1;
  5972.  
  5973.     if ((apap->fInTable == 1) && (apap->fTtp == 1) && apap->tableflag)
  5974.         {
  5975.         error(erroroutput,"cell and row end\n");
  5976. #if 0
  5977.         if (!clearedspecials)
  5978.             {
  5979.             decode_e_chp(&resetc);
  5980.             decode_e_specials(&reset,achp,a_list_info);
  5981.             clearedspecials=1;
  5982.             }
  5983. #endif
  5984.         fprintf(outputfile,"\n</tr>\n");
  5985.         ret=1;
  5986.         inarow=0;
  5987.         inacell=0;
  5988.         apap->tableflag=0;
  5989.         }
  5990.     else if ((apap->fInTable == 1)  && (apap->fTtp != 1) && apap->tableflag )
  5991.         {
  5992.         if (!clearedspecials)
  5993.             {
  5994.             decode_e_chp(&resetc);
  5995.             decode_e_specials(&reset,achp,a_list_info);
  5996.             clearedspecials=1;
  5997.             }
  5998.         if (cellempty == 1)
  5999.             fprintf(outputfile," ");
  6000.         fprintf(outputfile,"\n</td>\n");
  6001.         backgroundcolor[0] = '\0';
  6002.         inacell=0;
  6003.         apap->tableflag=0;
  6004.         chpsoff();
  6005.         error(erroroutput,"cell end\n");
  6006.         }
  6007.  
  6008.     if ( (inatable) && (!apap->fInTable) && (!inarow) )
  6009.         {
  6010.         error(erroroutput,"table ends here\n");
  6011. #if 0
  6012.         if (!clearedspecials)
  6013.             {
  6014.             decode_e_chp(&resetc);
  6015.             decode_e_specials(&reset,achp,a_list_info);
  6016.             clearedspecials=1;
  6017.             }
  6018. #endif
  6019.         fprintf(outputfile,"\n</table>\n");
  6020.         lastrowlen=0;
  6021.         inatable=0;
  6022.         }
  6023.  
  6024.     return(ret);
  6025.     }
  6026. void decode_e_specials(pap *apap,chp *achp,list_info *a_list_info)
  6027.     {
  6028.     int resetchp=0;
  6029.     chp reset;
  6030.     error(erroroutput,"decoding specials istd is %d\n",apap->istd);
  6031.     /*before a para ends, well reset all chars to original defaults*/
  6032.  
  6033.     init_chp(&reset);
  6034.     reset.fontcode=-2;
  6035.  
  6036.     error(erroroutput,"manual end chp\n");
  6037.  
  6038.     if (ignoreheadings ==0)
  6039.         {
  6040.         if ((apap->istd != 9) && (inah1 == 9))
  6041.             {
  6042.             inah1=0;
  6043.             if (!resetchp)
  6044.                 {
  6045.                 decode_e_chp(&reset);
  6046.                 resetchp=1;
  6047.                 }
  6048.                 
  6049.             fprintf(outputfile,"</H9>\n");
  6050.             }
  6051.         else if ((apap->istd != 8) && (inah1 == 8))
  6052.             {
  6053.             inah1=0;
  6054.             if (!resetchp)
  6055.                 {
  6056.                 decode_e_chp(&reset);
  6057.                 resetchp=1;
  6058.                 }
  6059.             fprintf(outputfile,"</H8>\n");
  6060.             }
  6061.         else if ((apap->istd != 7) && (inah1 == 7))
  6062.             {
  6063.             inah1=0;
  6064.             if (!resetchp)
  6065.                 {
  6066.                 decode_e_chp(&reset);
  6067.                 resetchp=1;
  6068.                 }
  6069.             fprintf(outputfile,"</H7>\n");
  6070.             }
  6071.         else if ((apap->istd != 6) && (inah1 == 6))
  6072.             {
  6073.             inah1=0;
  6074.             if (!resetchp)
  6075.                 {
  6076.                 decode_e_chp(&reset);
  6077.                 resetchp=1;
  6078.                 }
  6079.             fprintf(outputfile,"</H6>\n");
  6080.             }
  6081.         else if ((apap->istd != 5) && (inah1 == 5))
  6082.             {
  6083.             inah1=0;
  6084.             if (!resetchp)
  6085.                 {
  6086.                 decode_e_chp(&reset);
  6087.                 resetchp=1;
  6088.                 }
  6089.             fprintf(outputfile,"</H5>\n");
  6090.             }
  6091.         else if ((apap->istd != 4) && (inah1 == 4))
  6092.             {
  6093.             inah1=0;
  6094.             if (!resetchp)
  6095.                 {
  6096.                 decode_e_chp(&reset);
  6097.                 resetchp=1;
  6098.                 }
  6099.             fprintf(outputfile,"</H4>\n");
  6100.             }
  6101.         else if ((apap->istd != 3) && (inah1 == 3))
  6102.             {
  6103.             inah1=0;
  6104.             if (!resetchp)
  6105.                 {
  6106.                 decode_e_chp(&reset);
  6107.                 resetchp=1;
  6108.                 }
  6109.             fprintf(outputfile,"</H3>\n");
  6110.             }
  6111.         else if ((apap->istd != 2) && (inah1 == 2))
  6112.             {
  6113.             inah1=0;
  6114.             if (!resetchp)
  6115.                 {
  6116.                 decode_e_chp(&reset);
  6117.                 resetchp=1;
  6118.                 }
  6119.             fprintf(outputfile,"</H2>\n");
  6120.             }
  6121.         else if ((apap->istd != 1) && (inah1 == 1))
  6122.             {
  6123.             inah1=0;
  6124.             if (!resetchp)
  6125.                 {
  6126.                 decode_e_chp(&reset);
  6127.                 resetchp=1;
  6128.                 }
  6129.             fprintf(outputfile,"</H1>\n");
  6130.             }
  6131.         }
  6132.     error(erroroutput,"inah1 is now %d\n",inah1);
  6133.     if ((apap->justify != 2) && (inrightjust == 1))
  6134.         {
  6135.         inrightjust =0;
  6136.         error(erroroutput,"end of right\n");
  6137.         fprintf(outputfile,"\n</DIV>");
  6138.         }
  6139.  
  6140.     if ((apap->justify != 1) && (incenter == 1))
  6141.         {
  6142.         incenter =0;
  6143.         error(erroroutput,"end of center\n");
  6144.         fprintf(outputfile,"\n</CENTER>");
  6145.         }
  6146. #if 0
  6147.     do_indent(apap);
  6148. #endif
  6149.  
  6150.  
  6151.     }
  6152.  
  6153.  
  6154.  
  6155. void chpsoff()
  6156.     {
  6157.     chps=1;
  6158.     }
  6159.  
  6160. void chpson()
  6161.     {
  6162.     chps=0;
  6163.     }
  6164.